With this simple email rule:
$("#loginCliente").validate({
rules: {
loginNomEmail: { required: true, email: true },
}
});
In this input field, if we enter "test@" we got the validate error. But if we enter "test@teste" the plugin show that is an valid email.
How I can validate this field only if it is an valid email ?
i was having the same issue before and i think that adding a reg exp in the rules like this may be helpful
// this function is to accept only email
jQuery.validator.addMethod("accept", function(value, element, param) {
return value.match(new RegExp("^" + param + "$"));
},'please enter a valid email');
and in your rules you can just add this
$("#loginCliente").validate({
rules: {
loginNomEmail: { required: true,
email: true,
accept:"[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}" },
}
});
You can add your own method to validator:
jQuery.validator.addMethod("emailExt", function(value, element, param) {
return value.match(/^[a-zA-Z0-9_\.%\+\-]+@[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,}$/);
},'Your E-mail is wrong');
and use "emailExt" instead of "email":
$("#loginCliente").validate({
rules: {
loginNomEmail: {
required: true,
emailExt: true
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With