Reputation: 7979
I have posted a problem in the above link - regExpression.test.
Based on that I have done like bellow that also produces an error.
var regExpression=new RegExp("^([a-zA-Z0-9_\-\.]+)$");
alert (regExpression.test("11aa"));
Upvotes: 1
Views: 3269
Reputation: 655269
You can also use the literal RegExp syntax /…/
:
var regExpression = /^([a-zA-Z0-9_\-\.]+)$/;
By the way: The .
does not need to be escaped in character classes anyway. And if you put the range operator at the begin or the end of the character class or immediately after a character range, it doesn’t need to be escaped either:
var regExpression = /^([a-zA-Z0-9_.-]+)$/;
Upvotes: 3
Reputation: 630429
You need to escape your \
since you're declaring it with a string, like this:
var regExpression=new RegExp("^([a-zA-Z0-9_\\-\\.]+)$");
^ ^ add these
Upvotes: 3