tektipsismyfavorite
Technical User
I am working on a phone number validator and have an input that has maxChars = 12.
The format i'm going for is 999.999.9999
There's also a part that validates if it's a numeral.
I've tried this
called by onkeypress="return doPhone(this.value, event, 0)")
The problem i'm having is after the last ELSE right before the last return true.
For some reason if I enter 4 characters, it puts the "." between the 3rd and 4th character, like it should, but then it won't let me type any more numbers. it's like the field ends after it has 5 characters in it. What's goin on?
The format i'm going for is 999.999.9999
There's also a part that validates if it's a numeral.
I've tried this
Code:
function doPhone(currv, evt, decimal){
evt = (evt) ? evt : event;
var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
((evt.which) ? evt.which : 0));
if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46) {
return false;
}
if (charCode == 46) {
if (decimal == 0) {
return false;
} else {
if (currv.indexOf(".") != -1) {
return false;
}
}
} else if (currv.indexOf(".") != -1) {
var s = currv.substring(currv.indexOf("."));
if (s.length > decimal) {
return false;
}
}
if (charCode == 10){
var num = document.moreinfo.cell.value;
var len = num.length - 1;
if(document.moreinfo.cell.value.length == 4 || document.moreinfo.cell.value.length == 8){
document.moreinfo.cell.value = num.substring(0,len);
}
return true;
} else {
if(document.moreinfo.cell.value.length == 3 || document.moreinfo.cell.value.length == 7){
document.moreinfo.cell.value += ".";
}
return true;
}
}
The problem i'm having is after the last ELSE right before the last return true.
For some reason if I enter 4 characters, it puts the "." between the 3rd and 4th character, like it should, but then it won't let me type any more numbers. it's like the field ends after it has 5 characters in it. What's goin on?