I'm relatively new to Vue and have implemented email validation using the reg
expression in my Vue script data for this project. By utilizing
console.log(this.reg.test(this.email))
and observing the output while users input their email, the validation works correctly by returning true or false. However, I'd like the 'NEXT' button to become enabled only when console.log(this.reg.test(this.email))
is true.
View
<div id="app">
<h2>To-Dos:</h2>
<input type="email" v-model="email" placeholder="Enter your email address"/>
<button v-bind:disabled="isDisableComputed">NEXT</button>
</div>
Script
new Vue({
el: "#app",
data: {
email: '',
reg: /^(([^<>()\[\]\\.,;:\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,24}))$/
},
methods: {
toggle: function(todo){
todo.done = !todo.done
}
},
computed: {
isDisableComputed() {
if(this.reg.test(this.email)){
console.log(this.reg.test(this.email));
return false;
}
else{
console.log(this.reg.test(this.email));
return true;
}
},
}
})
You can view my code on JSFIDDLE here: