175
rated 0 times
[
178]
[
3]
/ answers: 1 / hits: 34339
/ 11 Years ago, thu, april 4, 2013, 12:00:00
I'm using this function to phone mask and works almost perfectly.
function mask(o, f)
{
v_obj = o;
v_fun = f;
setTimeout("execmask()", 1)
};
function execmask()
{
v_obj.value = v_fun(v_obj.value)
};
function mphone(v){
v=v.replace(/D/g,"");
v=v.substring(0, 11);
v=v.replace(/^(d{2})(d)/g,"(OXX$1) $2");
v=v.replace(/(d)(d{4})$/,"$1-$2");
return v;
}
Here I run the mask in the text field:
<input type="text" id="phone" name="phone" onkeypress="mask(this, mphone);" onblur="mask(this, mphone);" />
The problem is that I need to change this part of the code (OXX$1)
to (0XX$1)
.
Current situation:
No. Of Digits | Input Field |
---|---|
9 digit | (OXX99) 99999-9999 |
8 digit | (OXX99) 9999-9999 |
The correct formatting that I need:
No. Of Digits | Input Field |
---|---|
9 digit | (0XX99) 99999-9999 |
8 digit | (0XX99) 9999-9999 |
The amount of 8 or 9 digits is the choice of the user.
Changing O
to 0
, causes an error in the mask.
More From » regex