find special characters in string typescript code example
Example 1: how to check for special characters in javascript
var format = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/;
if(format.test(string)){
return true;
} else {
return false;
}
Example 2: regex to check if string contains special characters 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"));