Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4618176
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:13:44+00:00 2026-05-22T02:13:44+00:00

Possible Duplicates: Email Validation – Regular Expression What is the best regular expression for

  • 0

Possible Duplicates:
Email Validation – Regular Expression
What is the best regular expression for validating email addresses?

Hi All,

I have an email address roughly like this,

firstname.lastname@4domain.co.nz

Which doesn’t work with the regex I have here for email addresses. It doesn’t seem to like the 4 at the start of the domain.

private const string MatchEmailPattern =
        @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@" +
        @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\." +
        @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|" +
        @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";

Most other corner cases work well with this regex, all of the below are rejected,

        Assert.IsFalse(EmailValidator.IsValidEmailAddress("..@test.com"));
        Assert.IsFalse(EmailValidator.IsValidEmailAddress(".a@test.com"));
        Assert.IsFalse(EmailValidator.IsValidEmailAddress(".@s.dd"));
        Assert.IsFalse(EmailValidator.IsValidEmailAddress("ab@988.120.150.10"));
        Assert.IsFalse(EmailValidator.IsValidEmailAddress("ab@120.256.256.120"));
        Assert.IsFalse(EmailValidator.IsValidEmailAddress("2@bde.cc"));
        Assert.IsFalse(EmailValidator.IsValidEmailAddress("-@bde.cc"));
        Assert.IsFalse(EmailValidator.IsValidEmailAddress("..@bde.cc"));
        Assert.IsFalse(EmailValidator.IsValidEmailAddress("_@bde.cc"));

Any other regexes people can suggest for emails that will work with the above?

Also the above regex has the advantage that it works with addresses like this, and a lot of them don’t,

firstname.lastname_@gmail.com

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:13:45+00:00Added an answer on May 22, 2026 at 2:13 am

    You should use the MailAddress class, like this:

    try {
        address = new MailAddress(address).Address;
    } catch(FormatException) {
        //address is invalid
    }
    

    If you use this approach to validate the e-mail address, be aware, that this MailAddress accepts the display name part of the e-mail address as well, and that may be not exactly what you want to achieve. For example, it accepts this strings as valid e-mail addresses:

    • “user1@hotmail.com; user2@gmail.com“
    • “user1@hotmail.com; user2@gmail.com; user3@company.com“
    • “User Display Name user3@company.com“

    In these cases only the last part of the strings is parsed as the address, the rest before that is the display name. To get a plain e-mail address without any display name, you should check if the DisplayName property of the MailAddress instance is empty.

    bool isValid = false;
    
    try
    {
        MailAddress address = new MailAddress(emailAddress);
        isValid = (string.IsNullOrEmpty(address.DisplayName));
        // or
        //isValid = ((address.User + "@" + address.Host) == emailAddress);
    }
    catch (FormatException)
    {
        //address is invalid
    }
    

    Furthermore an address having a dot at the end, like “user@company.” is accepted by MailAddress either.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicates: What is the best regular expression for validating email addresses? Is there
Possible Duplicate: What is the best regular expression for validating email addresses? I'm using
Possible Duplicate: What is the best regular expression for validating email addresses? I am
Possible Duplicate: What is the best regular expression for validating email addresses? I've been
Possible Duplicate: Best practices for validating email address in Objective-C on iOS 2.0? I
Possible Duplicate: Validate email address in Javascript? I have javascript for email validation :
Possible Duplicate: Is there a php library for email address validation? Hi there, I
Possible Duplicate: Regexp recognition of email address hard? Hi, I would like to implement
Possible Duplicate: Email Address Validation for ASP.NET <input id=txtemail type=text /> private void btnDelete_Click(object
Possible Duplicate: Remove duplicates from a List<T> in C# i have a List like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.