Thursday, June 7, 2012

Auto Format (XXX-XXX-XXXX) Phone Number in Jquery


Phone Number:


------------Jquery-------------------
$('#txtboxID').keyup(function () {
var val = this.value.replace(/\D/g, '');
var newVal = '';
while (val.length > 3) {
if (val.length == 10) {
newVal += val.substr(0, 4);
return false;
} else {
newVal += val.substr(0, 3) + '-';
val = val.substr(3);
}
}
newVal += val;
this.value = newVal;
});
-----------------------

No comments:

Post a Comment