1 function ValidateSpecialCharacter() {
2 var code;
3 if (document.all) { //判断是否是IE浏览器
4 code = window.event.keyCode;
5 } else {
6 code = arguments.callee.caller.arguments[0].which;
7 }
8 var character = String.fromCharCode(code);
9 var txt=new RegExp("[ ,\`,\~,\!,\@,#,\$,\%,\^,\+,\*,\&,\\,\/,\?,\|,\:,\<,\>,\{,\},\(,\),\'',\;,\=,"]");
10 //特殊字符正则表达式
11 if (txt.test(character)) {
12 if (document.all) {
13 window.event.returnValue = false;
14 } else {
15 arguments.callee.caller.arguments[0].preventDefault();
16 }
17 }
18 }