How to restrict special characters.
function check(e) {
var keynum
var keychar
var numcheck
// For Internet Explorer
if (window.event)
{
keynum = e.keyCode
}
// For Netscape/Firefox/Opera
else if (e.which)
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)
//List of special characters you want to restrict
if (keychar == "'" || keychar == "`")
{
return false;
}
else {
return true;
}
}
Now let's have a look over how to call this special characters restriction function in a textbox.
For aspx server side textbox control
For html textbox control
You can restrict any other character or number other than special characters too, just by simply add it in the list of characters to be restricted such as for example I want to restrict the character a too then the code will be
if (keychar == "'" || keychar == "`" || keychar == "a")
So this is the way to handle and restrict the special characters being entered in textbox using javascript.
0 comments:
Post a Comment