问题
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