Created
February 24, 2016 06:47
-
-
Save johndavedecano/a945d6d94d472c922556 to your computer and use it in GitHub Desktop.
Block Special Characters while Typing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function RestrictSpaceSpecial(e) { | |
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(/^[a-zA-Z0-9-_]+$/); | |
if (exp.match(r)) { | |
return true; | |
} else { | |
window.event.keyCode = 0 | |
return false; | |
} | |
} | |
// onkeypress="javascript:return RestrictSpaceSpecial(event);" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment