Reputation: 153
I have this regular expression:
var regex = /^[-.:_A-Za-z0-9]*/;
But I need to test a string to see if it has any characters that do not match that expression.
I have tried
var regex =/^[^-.:_A-Za-z0-9]*$/;
But that did not catch the characters that I am looking for.
Basically, I need a regular expression that I can use in javascript to find any character that is not - . : . A-Z a-z or 0-9 in a javascript string variable.
thisShouldPass
thisShou[][]ldFail
Upvotes: 2
Views: 98
Reputation: 10777
I suspect you want to remove the anchors and the *
:
var regex =/[^-.:_A-Za-z0-9]/;
Upvotes: 3