Reputation: 3579
I tried this code as provided in https://v2.vuejs.org/v2/cookbook/form-validation.html.
validEmail: function (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);
}
Vuejs is saying that - error: Unnecessary escape character: \[ (no-useless-escape) at src/components/form.vue:125:65
which is the line var re = ...
What I am getting wrong here? I called this function like this.validEmail(this.modelname)
Upvotes: 2
Views: 3765
Reputation: 34306
The "error" (technically it's just a warning) is saying that you do not need to escape [
in the regex when it is inside a character set ([]
syntax) because its meaning is unambiguous (you can't create nested character sets); ]
, on the other hand, does need to be escaped because it will be interpreted as part of the regex syntax that ends the character set instead of a literal ]
character.
Simplified example:
/[\[]/
^ unnecessary escape
should be instead:
/[[]/
Upvotes: 3