Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

validate an email address ?

by Anonymous Monk
on Feb 16, 2001 at 21:08 UTC ( [id://58893]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to validate an emailaddress contained in $emailaddress.

I am trying to make sure that it contains at least @(text or numbers).(text or numbers)

I have been trying the following without success

$emailcheck=0; $_=$emailaddress; if ( !/\@([a-z][A-Z][0-9]\.+)([0-9][a-z][A-Z]+)/ ) { $emailcheck++; }

Does anyone have any ideas ?

Edit: 2001-03-03 by neshura

Replies are listed 'Best First'.
Re: validate an email address ?
by arturo (Vicar) on Feb 16, 2001 at 21:15 UTC

    If you want decent validation, try Email::Valid.

    If you want your code to be readable, please wrap it in <code> tags.

    Now, to the immediate problem: is this cut and pasted? Your regex (as posted) is attempting to find things that *DON'T* match your pattern, i.e. $emailcheck will only be incremented if the address isn't in the format you've specified. While we're at it, here's the syntax for checking $emailaddress directly, with a little of Perl's syntactic neatness thrown in:

    $emailcheck++ if $emailaddress =~ /@[a-z0-9]+\.[a-z0-9]+/i;

    HTH

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

      there's also RFC822 if email valid doesn't work.

      And doesn't japhy's OGRE have a "real" 822 validating regexp for a test case? a regexp that's, oh, 500 lines long?

        The version of Email::Valid on my machine (0.12) uses the RFC822 pattern.
Re: validate an email address ?
by chipmunk (Parson) on Feb 16, 2001 at 21:32 UTC
Re: validate an email address ?
by batmonk (Scribe) on Feb 16, 2001 at 21:52 UTC
Re: validate an email address ?
by Gloom (Monk) on Feb 16, 2001 at 21:16 UTC
    if( $emailaddress =~ m!\@[.a-zA-Z0-9]+\.[a-zA-Z0-9]+$! ) { $emailcheck++ }

    But it's too simple to really check an email address..

    Update

    I only tried to answer simply to the question and adviced him to look for a more serious solution
    ___________________
    Hope this helps
      This is wrong, for all the normal reasons. {grin} Please search the wealth of info available on this topic already, or even the other messages likely to pop up on this thread alone!

      -- Randal L. Schwartz, Perl hacker

        Amen.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://58893]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-19 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found