Saturday, August 9, 2008

Avoid unwanted characters using Javascript

function blockNumbers(e)
{

var key;
var keychar;
var reg;

if(window.event) { // for IE, e.keyCode or window.event.keyCode can be used
key = e.keyCode; }
else if(e.which) { // netscape
key = e.which; }
else { // no event, so pass through
return true; }

keychar = String.fromCharCode(key);
//alert(key);
if ( (key>=48 && key<=57) || (key==34) || (key==39) || (key==8) ) {
return true; }
else {
return false; }
}

No comments:

Popular Posts