-
I'm looking for a script that will take a form input and maintain a format such as:
(___) ___-____
It should only allow numeric input and make the correct placement of characters, so as they fill it out it becomes:
(55_) ___-____
(555) 5__-____
(555) 555-____
(555) 555-5555
And then cap it at 10 numbers.
I found one script that was for sale that does this and many other field formats, but I'm focused on just making it as small as possible and doing just this. Is there anything like this already available, or can someone throw me a handmade script?
Thanks,
Jordan
-
I THINK this is what you're looking for... it's an auto-tab function but field validation (i.e. numbers only) isn't included in this script, but could easily be added.
Javascript
=========================================
/* --------------------------------------------------- */
/* AUTO TAB */
/* --------------------------------------------------- */
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode;
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}
=================================
HTML Event
=================================
onkeyup="return autoTab(this, 3, event);"
The value "3" is how many characters before it jumps to the next field.
==================================
-
More like the phone number mask from Wiseblocks.
http://www.wiseblocks.com/input-comp...CTextMask.html
I just want the phone number mask, though. I want to avoid a giant library.
-
I wrote one of these once upon a time... I think Iost it, though, in various HD switches. I'll look into it and see if I can dig it up. It wasn't a long one -- it was something like 100 LOC or so.