Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to Validate Multiple Email Addresses in a long text field using Regular Expressions

I want the regular expression to validate multiple email address for a long text field separated by comma but validation should be put so that field should accept the data in the email ID format (ex: xyz@aig.com,@xyz@abc.in,xyz@abc.uk)only.

I have tried the regular expression:-

^([A-Za-z]+[A-Za-z0-9.-]+@(([aig.com])|([abc.in])|([abc.uk]))+\.[A-Za-z]{2,4}(\s*(;|,)\s*|\s*$))+$)

This expression is also accepting the email id if user enters (ex: abc@aig.uk,abc@aig.in)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use this to validate specified list:

^(?:(?:[A-Za-z][A-Za-z0-9.-]*@(?:aig\.com|abc\.in|abc\.uk))(?:,|$))*$

Worth noting: (?:aig\.com|abc\.in|abc\.uk) matches any of aig.com, abc.in, abc.uk.

In your attempt [] where not needed as [aig.com] matches a, acc.cc.s or any permutation of symbols inside square brackets.

Also (?:,|$) matches either , or end of the string.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading