Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Email Validation

by Kage (Scribe)
on Nov 14, 2001 at 21:53 UTC ( #125376=note: print w/replies, xml ) Need Help??


in reply to Email Validation

I found the absolute beth method of doing an E-Mail Validation is just to push the email address into a variable and do this:
if ($form{'email'} !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z0-9]+)(\]?) +$/) { $invalid="true"; } else { $invalid="false"; }
This checks to make sure it has a @, has text before the @, text after the @, and a . after the @, and checks to make sure it is only alphanumeric charactors and no spaces. Very efficient.

Replies are listed 'Best First'.
Re: Re: Email Validation
by $code or die (Deacon) on Nov 14, 2001 at 22:55 UTC
    This regex fails for many valid addresses and it will pass on some invalid ones. Try:
    postmaster@localhost (valid) @@domain.com (invalid) "my name" <myaddress@mydomain.com> (valid) "my name with spaces"@mydomain.com (valid) me@--.com (invalid)
    This checks to make sure it has a @, has text before the @, text after the @, and a . after the @, and checks to make sure it is only alphanumeric charactors and no spaces
    This is not the correct definition of a valid email address. Check RFC822 for the full specification.

    For me, the best method is to try sending an email to the address. If you don't want to do that then I'd follow the advice of the other posters, who suggest Mastering Regular Expressions, Email::Valid / RFC::RFC822::Address / Mail::Address or others.

    Update: I would also look at the FAQ: How do I check a valid mail address?

    Simon Flack ($code or die)
    $,=reverse'"ro_';s,$,\$,;s,$,lc ref sub{},e;$,
    =~y'_"' ';eval"die";print $_,lc substr$@,0,3;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://125376]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2018-08-14 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:









    Results (146 votes). Check out past polls.

    Notices?