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

  • Home
  • SEARCH
  • 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 553289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:35:21+00:00 2026-05-13T11:35:21+00:00

Based on this answer… Using a regular expression to validate an email address Which

  • 0

Based on this answer…
Using a regular expression to validate an email address

Which led me to this site…
http://fightingforalostcause.net/misc/2006/compare-email-regex.php

I’d like to use this regex for email validation for my ASP.NET MVC app:

/^[-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?$/iD

Unfortunately, I get this error

System.ArgumentException was unhandled by user code
Message=”parsing \”/^[-_a-z0-9\’+$^&%=~!?{}]++(?:\.[-_a-z0-9\’+$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?

Has anyone ever converted this to be usable by .NET’s Regex class, or is there another .NET regular expression class that is a better fit with PHP’s preg_match function?

  • 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-13T11:35:22+00:00Added an answer on May 13, 2026 at 11:35 am

    The problem with your regular expression in .NET is that the possessive quantifiers aren’t supported. If you remove those, it works. Here’s the regular expression as a C# string:

    @"^[-_a-z0-9\'+*$^&%=~!?{}]+(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*@(?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d+)?$"
    

    Here’s a test bed for it based on the page you linked to, including all the strings that should match and the first three of those that shouldn’t:

    using System;
    using System.Text.RegularExpressions;
    
    public class Program
    {
        static void Main(string[] args)
        {
            foreach (string email in new string[]{
                "l3tt3rsAndNumb3rs@domain.com",
                "has-dash@domain.com",
                "hasApostrophe.o'leary@domain.org",
                "uncommonTLD@domain.museum",
                "uncommonTLD@domain.travel",
                "uncommonTLD@domain.mobi",
                "countryCodeTLD@domain.uk",
                "countryCodeTLD@domain.rw",
                "lettersInDomain@911.com",
                "underscore_inLocal@domain.net",
                "IPInsteadOfDomain@127.0.0.1",
                "IPAndPort@127.0.0.1:25",
                "subdomain@sub.domain.com",
                "local@dash-inDomain.com",
                "dot.inLocal@foo.com",
                "a@singleLetterLocal.org",
                "singleLetterDomain@x.org",
                "&*=?^+{}'~@validCharsInLocal.net",
                "missingDomain@.com",
                "@missingLocal.org",
                "missingatSign.net"
            })
            {
                string s = @"^[-_a-z0-9\'+*$^&%=~!?{}]+(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*@(?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d+)?$";
                bool isMatch = Regex.IsMatch(email, s, RegexOptions.IgnoreCase);
                Console.WriteLine(isMatch);
            }
        }
    }
    

    Output:

    True
    True
    True
    True
    True
    True
    True
    True
    True
    True
    True
    True
    True
    True
    True
    True
    True
    True
    False
    False
    False
    

    A problem though is that it fails to match some valid email-addresses, such as foo\@bar@example.com. It’s better too match too much than too little.

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

Sidebar

Related Questions

I'm building an ogre3d tutorial based on this setup http://www.ogre3d.org/wiki/index.php/SettingUpAnApplication#XCode I've followed all steps
I have been writting a keyword search script based on this tutorial: http://www.hackosis.com/2007/11/06/howto-simple-search-engine-with-php-and-mysql/ Like
Based on this question it appears that the default template for CheckStyle will allow
Based on this question I don't want to litter my ready stuff waiting for
I want to create dynamic content based on this. I know it's somewhere, as
I have up to 4 files based on this structure (note the prefixes are
Based on the response to this question: Why does C++ have header files and
This question is based on another question of mine (thankfully answered). So if in
This request is based in MS Access VBA. I would like to know what
By this, I don't mean PC-based development environments (like Visual Studio) for developing and

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.