Answer the question
In order to leave comments, you need to log in
Regex not working in Vue2?
I needed to do email validation and vscode highlights the regex as an error.
regex
in computed is regex:
computed:{
regex(){
return new RegExp(/^(([^<>()\[\]\\.,;:\[email protected]"]+(\.[^<>()\[\]\\.,;:\[email protected]"]+)*)|(".+"))@((\[[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,24}))$/)
}
},
if (!this.regex.test(this.email)) {
this.emailErr = true;
let vm = this;
setTimeout(() => {
vm.emailErr = false;
}, 1000);
Answer the question
In order to leave comments, you need to log in
Regex not working in Vue2?
Yes, the creators of Vue cut regular expressions out of JS.
Try it:
computed:{
regex(){
return /^(([^<>()\[\]\\.,;:\[email protected]"]+(\.[^<>()\[\]\\.,;:\[email protected]"]+)*)|(".+"))@((\[[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,24}))$/;
}
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question