Code Snippet posted by:
Blessybaby | Posted on: 6/1/2009 | Category:
JavaScript Codes | Views: 18132 | Status:
[Member]
|
Alert Moderator
function RestrictChar()
{
get the keycode when the user pressed any key in application
var exp = String.fromCharCode(window.event.keyCode)
//Below line will have the special characters that is not allowed you can add if you want more for some characters you need to add escape sequence
var r = new RegExp("[-_,/'().0-9a-zA-Z \r]", "g");
if (exp.match(r) == null)
{
window.event.keyCode = 0
return false;
}
}
in code behind we need to add below code for calling this function
txtuser.Attributes.Add("onkeypress", "javascript:return RestrictChar()");
Found interesting? Add this to: