开发者

Regular Expression to check valid email address [duplicate]

开发者 https://www.devze.com 2023-01-29 16:24 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: Validating an email Address in C#
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

Validating an email Address in C#

Hi,

I'm trying to create regular expression to check valid email address, but the following code not returning any output.

foreach(Match m in (Regex.Matches("Jack@yahoo.com","^([a-zA-Z])+(?:\\d)*?@\\1\\.\\1{2,4}$")))
    {   
        Console.WriteL开发者_高级运维ine("{0} found at index{1}",m.Value,m.Index);
    }

Could anyone please tell what's wrong I'm doing?


Try this

    foreach(Match m in (Regex.Matches("Jack@yahoo.com","^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$")))
    {   
        Console.WriteLine("{0} found at index{1}", m.Value, m.Index);
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消