In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
小编给大家分享一下正则表达式RegExp判断文本框中是否包含特殊符号的方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
前言
有时,我们希望判断文本框中用户输入的字符是否含有特殊符号(*/#$@),就像用户注册时密码框的填写。
demo
利用 RegExp 对象,能很优雅的实现以上需求:
// even(文本框内容)function (even) { // 规则对象(flag) var flag = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].《》/?~!@#¥……&*()--|{}【】';:""'。,、? ]") // 判断 even 是否包含特殊字符 if(flag.test(even)){ console.log('包含!') }else{ console.log('不包含!') } }
flag 规则对象中还有很多其他特殊字符,这里的demo已经足够使用,如项目另有需求加入其他特殊字符即可。
ps:js中用正则表达式 过滤特殊字符 ,校验所有输入域是否含有特殊符号
function stripscript(s) { var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\]./?~!@#¥……&*()--|{}【】';:""'。,、?]") var rs = ""; for (var i = 0; i < s.length; i++) { rs = rs+s.substr(i, 1).replace(pattern, ''); } return rs; }
如何只是判断是否存在特殊字符串
if(pattern .text(str)){return true}else{return false}以上是"正则表达式RegExp判断文本框中是否包含特殊符号的方法"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.