.Net Links

Monday, March 15, 2010

How to allow Alphabets,Periods,Dash(-) in Javascript

The below script will allow only Alphabets,Periods,Dash(-) to be entered in Text Box

Works in IE,FF,Chrome

function blockNumbers(e) {

//In FireFox Back-Space Key Code=8 , Tab KeyCode=0
//In IE Back-Space Key Code=Null , Tab KeyCode=9

isIE = document.all ? 1 : 0
keyEntry = !isIE ? e.which : event.keyCode;
if(!(((keyEntry >= '65') && (keyEntry <= '90')) || ((keyEntry >= '97') && (keyEntry <= '122')) || (keyEntry == '46') || keyEntry == '45' || keyEntry == '0' || keyEntry == '8' || keyEntry == '9'))
{
alert("Only Alphabets,Periods,Dash allowed");
return false;
}
}


Labels: , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home