Created
June 4, 2013 11:04
-
-
Save lvjian700/5705158 to your computer and use it in GitHub Desktop.
Illegal character validation
This file contains hidden or 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
| <html> | |
| <head> | |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
| <title>Insert title here</title> | |
| </head> | |
| <body> | |
| <input type="text" id="taskName" value="" /> | |
| <script type="text/javascript" src="js/jquery-1.4.2.js"></script> | |
| <script type="text/javascript"> | |
| var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]"); | |
| $('#taskName').keypress(function(e) { | |
| var keyCode = e.keyCode; | |
| var keyChar = String.fromCharCode(keyCode); | |
| //匹配特殊字符 | |
| var match = pattern.exec(keyChar); | |
| if(match != null) { | |
| //阻止键盘输入 | |
| e.preventDefault(); | |
| }; | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment