使用jQuery检查是否出现特殊字符

编程入门 行业动态 更新时间:2024-10-10 04:22:30
本文介绍了使用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.

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

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

更多推荐

使用jQuery检查是否出现特殊字符

本文发布于:2023-11-27 18:39:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639148.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:特殊字符   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!