I know how to validate if a user has left an input field on an html form blank. What I need is for the user to input the phone field in a consistant manner, xxx-xxx-xxxx.
Can the input field be formated, similar to an input mask in a database field?
yes it can be done. For that to be possible you have to learn about onkeypress as well as onchange wich are events that are triggered by the input field. You can attach functions to these events that will execute automatically. What you put inside these functions will dictate how the field works. Gary
mine isn't that complex - the anyMask script is more robust...anyway, here's mine explained if you want:
this line uses a regular expression to check for numeric values only, and returns false if a non-numeric value is found:
[tt]
if (/\D/g.test(data)) return false;
[/tt]
next we loop through the arguments array passed to formatNum()...if we're on an odd numbered argument array element, we add the amount of characters to the result string from the data string as specified by that array element, removing that character from the data string as we go along.
if we're on an even array index, we add that element's value to the results string.
finally, after all the arguments we add whatever is left of the data string to the result string.
so:
formatNum(this,3,'-',2,'+');
does this:
-take the first 3 characters of the data string and add to the result string
-add a '-' to the result string
-take two more characters from data string and add to result string
-add a '+' to the result string
-add the remainder of the data string to the result string
=========================================================
if (!succeed) try();
-jeff
just my coder-geek version of "if at first you don't succeed, try and try again."
=========================================================
if (!succeed) try();
-jeff
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.