ikiw
ikiw

Reputation: 358

Can't figure out why jsLint throws unescaped '[' in regex

This is my function,

function validateEmail(email) { 
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);

}

JsLint Throws unescaped '[' in re declaration ! is there anything wrong with the construction of regex ?

Upvotes: 0

Views: 945

Answers (1)

sp00m
sp00m

Reputation: 48807

In the first part of your regex ([^<>()[\]\\.,;:\s@\"]+), you may need to escape the inner [:

[^<>()\[\]\\.,;:\s@\"]+
       ^

This must be done in the next part of your regex as well.

Upvotes: 4

Related Questions