Regex Email validation

后端 未结 30 1215
北海茫月
北海茫月 2020-11-22 12:16

I use this

@\"^([\\w\\.\\-]+)@([\\w\\-]+)((\\.(\\w){2,3})+)$\"

regexp to validate the email

([\\w\\.\\-]+) - this is f

30条回答
  •  春和景丽
    2020-11-22 12:28

    I think @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$" should work.
    You need to write it like

    string email = txtemail.Text;
    Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
    Match match = regex.Match(email);
    if (match.Success)
        Response.Write(email + " is correct");
    else
        Response.Write(email + " is incorrect");
    

    Be warned that this will fail if:

    1. There is a subdomain after the @ symbol.

    2. You use a TLD with a length greater than 3, such as .info

提交回复
热议问题