Regexp determines whether a text box contains special symbols



Sometimes, we want to determine whether the character entered by the user in the text box contains a special symbol (* / # [email protected]), just like filling in the password box when the user registers.


With regexp object, the above requirements can be realized elegantly

//Even (text box content)
function (even) {
 //Rule object (flag)
 var flag = new RegExp("[`[email protected]#$^&*()=|{}':;',\\[\\].<>《》/?~!@#¥……&*()——|{}【】‘;:”“'。,、? ]")
 //Determine whether even contains special characters
 console.log ('contains! )
 console.log ('not included! )

There are many other special characters in the flag rule object. The demo here is enough to use. If the project needs other special characters, you can add other special characters.

PS: in PS: JS, regular expressions are used to filter special characters and check whether all input fields contain special symbols

function stripscript(s) 
var pattern = new RegExp("[`[email protected]#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]") 
var rs = ""; 
for (var i = 0; i < s.length; i++) { 
rs = rs+s.substr(i, 1).replace(pattern, ''); 
return rs; 

How to just judge whether there is a special string

if(pattern .text(str)){
return true}
return false


The above is a regular expression (regexp) introduced by Xiaobian to judge whether there are special symbols in the text box. I hope it will be helpful to you. If you have any questions, please leave me a message, and the editor will reply you in time. Thank you very much for your support to the developeppaer website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!

Recommended Today

How to use pycharm debug? Tutorial for debugging pycharm

How does pycharm debug single step debugging? In the operation of developing the script of pycharm software tool, we need to do the operation of debug step-by-step debugging in the current. Debug is the most commonly used operation to find problems. Let’s take a look at the skills of pycharmdebug step-by-step debugging. JetBrains pycham Pro […]