regular expression to check if string has only selected special characters in javascript code example
Example: regex to check if string contains special characters javascript
var format = /[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
// ^ ^
document.write(format.test("My@string-with(some%text)") + "<br/>"); //true
document.write(format.test("My string with spaces") + "<br/>"); //true
document.write(format.test("MyStringContainingNoSpecialChars")); //false