validate multiple email addresses in ASP.NET

Bill Johnson 11 Reputation points
2022-10-27T11:10:12.54+00:00

Hi,
Which best way in ASP.NET to validate multiple email address in cc field ?
I'm using this regular expression:
^[a-zA-Z][\w.-][a-zA-Z0-9]@[a-zA-Z0-9][\w.-][a-zA-Z0-9].[a-zA-Z][a-zA-Z.]*[a-zA-Z]$

but it's failing.
Example of what I would like to achieve:
email1@Stuff .com; email2@Stuff .com

TIA

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,362 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 27,721 Reputation points Microsoft Vendor
    2022-10-28T02:30:37.787+00:00

    Hi @Bill Johnson ,
    you can try this:

    ^(([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25}(($)|( *;+ *$)|( *;+ *(?=[a-zA-Z0-9_\-\.]))))*$  
    

    This regular expression allows email addresses to be separated by semicolons and spaces, and an optional semicolon is allowed.

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments