checking for any occurrence of special characters with jQuery

≡放荡痞女 提交于 2019-12-25 01:43:35

问题


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.


回答1:


Try this:

/[!@#$%\^&*(){}[\]<>?/|\-]/

You only need to escape the ]. Inside a character class ([]), the other characters are interpreted literally.

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



来源:https://stackoverflow.com/questions/10505772/checking-for-any-occurrence-of-special-characters-with-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!