i am stuck in a problem…This is my code which restricts special characters but i want a logic which will restricts special characters,numerics but allow alphanumeric values…
for eg:
- valid : a1,4r,aa.
-
invalid : w@,12,@!.
function check(e)
{
var keynum;
var keychar;
var numcheck;
if(window.event) // IE
{
keynum = event.keyCode;
}
else if(e.which) // netscape/Firefox/opera
{
keynum = e.which;
}
//condition for backspace(8) Key
if(keynum != 8)
{
keychar = String.fromCharCode(keynum);
numcheck = /[a-zA-Z0-9]*[a-zA-Z]+[a-zA-Z0-9]*/;
return numcheck.test(keychar);
}
else
{
return true;
}
}
User id : <input type="text" id="txtname" name="txtname" onkeypress="return check(event)"/>
I believe this would satisfy your need.
This would restrict only numbers such as 12, 13, etc., would now allow any special character, and as required, would allow words containing alphabets and numbers both such as asd12, 12asd12, 12asd, etc.