Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #regex #check #string #special #characters #javascript
ADD COMMENT
Topic
Name
3+2 =