I'm using a script to validate an email address. This is based on HTML5 validation and jQuery validation. Now I noticed that email addresses like name@hotmail.c
are validated correctly. However this email address is not a valid email address.
If I check this email address on syntax at through this website: http://cobisi.com/email-validation/validate-address, it tells me that the syntax is incorrect.
Email addresses with the domain .c
are not valid, however the default HTML5 and jQuery validator think they have a valid syntax.
I wrote a small example on JSFIDDLE: http://jsfiddle.net/kvALH/
Below you will find the email part of my jQuery validation that I use in the form.
$('#form-validate').validate({
rules: {
email: {
required: true,
email: true
}
},
How can I get this email validation working correctly? Do I need to write my own validator method for email?
Edit
I understand that a domain hotmail.c
could be correct, but the tld just doesn't exists. All tld's have 2 characters or more, so I'm wondering why the HTML5 validation allows 1 character in the domain!
To solve my problem i understand I need another validation so I used the regex from this thread (Validate email address in JavaScript?). Added a method to the jQuery validation and that seems to solve my issue.
JSFIDDLE: http://jsfiddle.net/kvALH/1/
jQuery.validator.addMethod("emailCustom", function (value, element, params) {
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(value);
}, "Please enter a valid email address.");
$('#form-validate').validate({
rules: {
email: {
required: true,
emailCustom: true
}
},
However I still think it's strange why the default validation just excepts this one character domain.