简体   繁体   中英

Mobile Number Masking using Javascript?

I want to use masking for Mobile Number in javascript.In this masking, I want to fix (+91) then user can input mobile number(10 digit number)

<label>Phone Number</label>
<input type="button" value="Turn on Mask" id="maskon" />
<input id="phone" type="text" value="" />

$("#maskon").click(function(){
    $("#phone").mask("(+91) 9999-999999");
});

If I am using the given masking then I am able to put any digit in place of 9 instead of it I want to have (+91) as fixed.

Is there any idea to solve this problem? Thanks in Advance!!

I do not think that there is an option for making first few digits fixed for mask plugin.

However you could also write keyup event for textbox and write a regex that verifies that first three digits are +91. You can use this regex for that. /(\\+\\d{2})/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM