Preface
Sometimes, we want to determine whether the characters entered by the user in the text box contain special symbols (*/#$@), just like filling in the password box when the user registers.
demo
Using RegExp objects, the above requirements can be achieved elegantly:
// even(text box content)function (even) { // Rule object (flag) var flag = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>《》/?~!@#¥……&*()——|{}【】‘;:”“'。,、? ]") // Determine whether even contains special characters if((even)){ ('Include! ') }else{ ('Not included! ') } }
There are many other special characters in the flag rule object, and the demo here is enough to use. If the project needs to add other special characters.
Another way
js regularity determines whether special symbols are included
function chack_name(str){ var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>《》/?~!@#¥……&*()——|{}【】‘;:”“'。,、? ]"); if ((str)){ return true; } return false; }
Summarize
The above is the JS Regularity (RegExp) introduced by the editor to determine whether the text box contains special symbols. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!
If you think this article is helpful to you, please reprint it. Please indicate the source, thank you!