javascript code to check special characters

后端 未结 6 1769
后悔当初
后悔当初 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:04

    You could also do it this way.

    specialRegex = /[^A-Z a-z0-9]/ specialRegex.test('test!') // evaluates to true Because if its not a capital letter, lowercase letter, number, or space, it could only be a special character

提交回复
热议问题