Click here to Skip to main content
15,908,661 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
I am trying to mask the input of the mobile number so i am doing something like this
HTML
("#mobNum").mask("(+91) 999-999-9999)

this mask is equivalent to this input
prefix +91 then followed by 3 digits followed by another 3 digits and then 4 digits.
so it is something like this +91 987-569-4869
So i want to prefix (+91) in the front of the text box automatically
how can i achieve this
Posted

1 solution

You can add a keyup handler to add the prefix.

JavaScript
$("#mobNum").keyup(function(){
    var prefix = "+91"

    if(this.value.indexOf(prefix) !== 0 ){
        this.value = prefix + this.value;
    }
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900