如果我有一组特殊字符,例如:!@#$%^&*(){}[]<>?/|-如何检查字符串(或字段值)中是否存在任何这些特殊字符?尝试添加一种方法jQuery验证程序插件,如果其中存在任何一个,该插件将拒绝该字段.我意识到这要求很多,正则表达式正在杀死我.
If I have a set of special characters like: !@#$%^&*(){}[]<>?/|- how could I check for existence of any of these in a string ( or field value)? Trying to add a method jQuery validator plugin that would reject the field if any of them are present. I realize this is asking for a lot, regex is just killing me.
推荐答案尝试一下:
/[!@#$%\^&*(){}[\]<>?/|\-]/您只需要转义].在字符类([])中,其他字符将按字面意义进行解释.
You only need to escape the ]. Inside a character class ([]), the other characters are interpreted literally.
更多信息: www.regular-expressions.info/charclass.html(在字符类内部的元字符"下)
More info: www.regular-expressions.info/charclass.html (Under "Metacharacters Inside Character Classes")
更多推荐
使用jQuery检查是否出现特殊字符
发布评论