Versions
vee-validate: 2.1.0-beta.2
vue: 2.5.7
Description
Used the email validation but it doesn't consider some valid emails such as:
- admin@gmail.com
It considers:
- admin@gmail.co
- admin1@gmail.com
- admin@gmail1.com
- admin@gmail.net
- admin@gmail.ne
Here's the code snippet:
[<input type="email"
id="email"
name="email"
class="form-control"
placeholder="Email "
v-model="user.email"
v-validate="'required|email'"
/>
<span class="error-msg" v-show="errors.has('email')">{{ errors.first('email') }}</span>][1]
See image for reference: https://i.stack.imgur.com/Dpz4F.png
---------------[UPDATE]:---------------
I override the email rule and now here it is:
const email = {
getMessage(field, args) {
return `The ${field} must be a valid email`;
},
validate(value, args) {
const EMAILREG = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
console.log(EMAILREG.test(value));
console.log(VeeValidate.Rules.email(value));
return VeeValidate.Rules.email(value) || EMAILREG.test(value);;
}
};
VeeValidate.Validator.extend('email', email);
What this custom rule is doing is even if it fails in the email validation of vee-validate, if it's true in the regEx validation, it will accept it. However, it consider admin@a as a valid email address.