How to validate an email address using a regular expression ?

How to validate an email address using a regular expression ?

Asked on December 14, 2018 in Regex.
Add Comment

  • 2 Answer(s)

    This will give you better way:

    RFC 822 flexible regex is ineffective and confusing . favorably, RFC 822  was twice and the present  specification for email addresses is RFC 5322.

    RFC 5322 flexible regex  found on top of the page at but uses the IP address pattern that is floating around the internet with a bug  allows 00 for any  unsigned byte decimal values in a dot-delimited address, which is illegal. Rest appears to be consistent with the RFC 5322 grammar and passes several tests using grep -Po, including cases domain names, IP addresses, bad ones, and account names with and without quotes.

    Regulate the 00 bug in the IP pattern, we gather a working and fairly fast regex. Scrape the rendered version, not the markdown, for actual code.

    The most practical  patterns in Perl and PCRE regex library used example in PHP can correctly parse RFC 5322 without a hitch. Python and C# can do this , but they use a different syntax from first two.

    Is important to understand that validating the RFC tells absolutely nothing about whether that address actually exists at the supplied domain, or whether the person entering the address is its true owner. People sign others up to mailing lists this way all the time. Fixing that requires a fancier kind of validation that involves sending that address a message that includes a confirmation token meant to be entered on the same web page as was the address.

    Tokens are the only way to know  address of the person entering it. for this only mailing lists now use that mechanism to confirm sign-ups.

    There is no better than all the other non-RFC patterns. It is smart enough to handle even RFC 822, let alone RFC 5322.

    you want to get fancy and pedantic, implement a complete state engine. A regular expression only act as a rudimentary filter. The problem with regular expressions is that telling someone that perfectly valid e-mail address is invalid  because your regular expression cannot handle rude and impolite from the user’s perspective. A state engine can  do both validate and even correct e-mail addresses that would  considered invalid  according to each RFC. 

    Answered on December 14, 2018.
    Add Comment

    You  can use this:

    In this,all depends on how accurate you are.Try to keep out things like bob @ (spaces in emails) or steve (no domain at all) or [email protected] (no period before .com), use this:

    ^\[email protected]\S+\.\S+$/

    Assured, it will match things are not valid email addresses, but it’s a matter of playing the 90/10 rule

    Answered on December 15, 2018.
    Add Comment

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.