Your regex also disallows .info and .name BTW. If you're not going to use a module, at least follow the RFCs.

I recommend Email::Address or Regexp::Common::Email::Address. I'd also encourage you to look into Mail::Message::Field::Full, Data::Validate::Email, Email::AddressParser or maybe Email::Valid as previously mentioned. Those are maintained for us all to use, and get updated whenever they need to be. It sure beats everyone doing something different. I can only recommend two specifically, because I can't recall having used the others.

If you're having issues getting modules from CPAN (or PPM), please make a new post regarding those problems.

If you're really needing to have a regex in your own code rather than using a module, you can get the regex for a valid email from Email::Address or Regexp::Common::Email::Address. I'd recommend against doing it that way, because you might need to update manually again in the future. CPAN is your friend, and it makes updating to newer versions of modules pretty easy.

You might want to note that Email::Valid uses Mail::Address, and the author of Mail::Address states that it only covers 95% of valid cases. The author of that recommends Mail::Message::Field::Full. Email::Address doesn't have this particular issue, as it is designed to the RFC 2822 spec. That's why I mildly recommend against Email::Valid and Mail::Address.


In reply to Re: checking email syntax by mr_mischief
in thread checking email syntax by powerhouse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.