How can I make a textbox only accept a valid email?

This question already has an answer here:

  • C# code to validate email address 34 answers

  • .NET可以为你做到这一点:

            try
            {
                var eMailValidator = new System.Net.Mail.MailAddress("xyz@blabla.com");
            }
            catch (FormatException ex)
            {
                // wrong e-mail address
            }
    

    检查Mailadress课程

        var test = new MailAddress("emailadres");
    

    If you're developing a web app, modern browsers support HTML5, so you can use <input id="txtEmail" type="email" runat="server" /> instead of a TextBox and it will validate the input is an email in the browser (but you should also validate it in your code). Use txtEmail.Value to get the text string.

    链接地址: http://www.djcxy.com/p/92836.html

    上一篇: 如何使用正则表达式处理长电子邮件地址?

    下一篇: 如何让文本框只接受有效的电子邮件?