Javascript Check Numeric , Get Numeric , Enter Only Numeric function
function isNumberKey(t)
{
if(t.value == 0 || t.value == '0')
t.value = 'a';
var patt1 = /(\d{3}).*(\d{3}).*(\d{4})/;
var patt2 = /^\((\d{3})\).(\d{3})-(\d{4})$/;
var str = t.value;
var result;
if (!str.match(patt2))
{result = str.match(patt1);
if (result!= null)
{t.value = t.value.replace(/[^\d]/gi,'');
//str = '(' + result[1] + ') ' + result[2] + '-' + result[3];
t.value = str;
}else{
if (t.value.match(/[^\d]/gi))
t.value = t.value.replace(/[^\d]/gi,'');
}}
}
ex: onkeyup="isNumberKey(this);"
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home