I have a recipient textbox that allows to enter an email address and send to the person.As you know, there are regex to be considered when someone enters an email. For example, an email without @
is not an valid email.
So I wrote a function that checks the regex of an email like this:
//check email address
function validateEmail(email) {
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(email);
}
So if I write test@hotmail.com
then this would be valid and test@@@hotmail.com
would not be valid. Yes this works fine with no issue. However, in my textbox I am allowed to send to multiple recipients in this form:
test@hotmail.com,test123@hotmail.com,....
So if I enter the above,it will treat it as invalid but seeing that I am bad in regex expression, is there a way to allow this to go through?
Edit:
This is how my regular expression looks like:
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,}))(?:$|(?=,)))/;