web analytics

Regular Expressions in C#

Options
@2017-09-29 13:35:19

Validating email format using regular expression in C#

The following code example uses the static Regex.IsMatch method and a regular expression to verify that a string is in valid e-mail format.

bool IsValidEmail(string strIn)

{

     // Return true if strIn is in valid e-mail format.

     return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");

}

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com