special character match in string javascript code example
Example 1: regex special characters javascript
var regex = /^[a-zA-Z0-9!@#\$%\^\&*\)\(+=._-]+$/g
Example 2: does string contain special charactors javascript
var format = /[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
// ^ ^
document.write(format.test("My@string-with(some%text)") + "<br/>");
document.write(format.test("My string with spaces") + "<br/>");
document.write(format.test("MyStringContainingNoSpecialChars"));