I'm using jquery.validate.js to validate the Email Input of the Formular.
It's working well, but I'm suprised that it's excepting emails as valid with the following format: name@domain
In my opinion there is missing a .TLD, no?
I checked the function inside the jquery.validate.js file. They are referencing the specification from www.whatwg.org for a valid email Adress. On the site it says that a valid email address should have the format name@doman.tld
The JS Regex inside jquery.validate.js is the following:
email: function( value, element ) {
return this.optional( element ) || /^[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])?)*$/.test( value );
},
How do I use a custom Regex that validates if the email includes a .TLD?
I specified the custom validation method as following:
jQuery.validator.addMethod("customemail", function(value, element) {
return this.optional(element) || /^(([^<>()[\]\\.,;:\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,}))$/.test(value);
}, "Please enter a valid email address.");
The function to validate the form is the following:
$("#subscription-form").validate({
});
What do I need to include, so the script uses my custom method instead of the email method?