采用正则表达式的方法,判断字符中是否包含有特殊字符:
function containSpecial( s ) { var containSpecial = RegExp(/[(\ )(\~)(\!)(\@)(\#) (\$)(\%)(\^)(\&)(\*)(\()(\))(\-)(\_)(\+)(\=) (\[)(\])(\{)(\})(\|)(\\)(\;)(\:)(\')(\")(\,)(\.)(\/) (\<)(\>)(\?)(\)]+/); return ( containSpecial.test(s) ); }
当返回的结构为true时,说明包含特殊字符。