使用jQuery检查是否出现特殊字符 [英] checking for any occurrence of special characters with jQuery

查看:651
本文介绍了使用jQuery检查是否出现特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一组特殊字符,例如:!@#$%^&*(){}[]<>?/|-如何检查字符串(或字段值)中是否存在任何这些特殊字符?尝试添加一种方法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.

更多信息: http://www.regular-expressions.info/charclass.html(在字符类内部的元字符"下)

More info: http://www.regular-expressions.info/charclass.html (Under "Metacharacters Inside Character Classes")

这篇关于使用jQuery检查是否出现特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆