javascript code to check special characters

后端 未结 6 1746
后悔当初
后悔当初 2020-12-08 10:45

I have JavaScript code to check if special characters are in a string. The code works fine in Firefox, but not in Chrome. In Chrome, even if the string does not contain spec

6条回答
  •  抹茶落季
    2020-12-08 11:10

    You can test a string using this regular expression:

    function isValid(str){
     return !/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g.test(str);
    }
    

提交回复
热议问题