Hi guys,
This is a tip on how validate a email field with one or more emails, using column or semi column. I was developing a validator for a ASP.net MVC3 with attributes using JavaSctipt/jQuery as well, and I developed this JavaScript function to validate email from 1 to N.
Basically I get an array of emails and go through the array looking for an invalid email based on a regular expression, if I find an invalid email I set the return value to be invalid or false.
See below the JavaScript Function that does the validation:
function validEmail(value) { var valid = true; var emails = value.replace(';', ',').split(","); jQuery.each(emails, function () { if (jQuery.trim(this) != '') { if (!jQuery.trim(this).match(/^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$/i)) valid = false; } }); return valid; };
Although I use this function with ASP.net MVC3, you can use this function on other project’s types, after all we know the JavaScript and jQuery’s power.
Obviously you can change or adapt this JavaScript function for your need.
Know more about JavaScript.
Know more about jQuery.
Thanks for reading.
Like and Share if you found it may be useful to someone you know!
Would you like to check the Portuguese version?
Clique on the Brazilian flag ->