Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: email check

by bronto (Priest)
on Jul 19, 2002 at 09:39 UTC ( [id://183172]=note: print w/replies, xml ) Need Help??

in reply to email check

As told by others, you should check the RFC or the module, or the module code. Anyway, if you are reinventing the wheel to learn something new, I'll tell you how I'd do it in the simplest case:

First of all, there should be just one "@", and if you want to avoid source routing you should also be sure there are no "%" on the right of the @.

you should check that there actually are characters before the @

top level domain should be two, three or four alphabetical chars (or you should get a list of TLD and check for them; guess how -hint: use an hash).

you should really have something more than only a top level domain on the right of @: a dot must be there, and there should be at least one alphanumeric character (plus the "-") between @ and the dot

Last but not least: no spaces are allowed

So, a regexp could be:

use strict ; use warnings ; my @addresses = qw( me@here me@here@there@everywhere why@ ; foreach (@addresses) { print "$_ is " ; print /^\S+\@([a-z-]+\.)+[a-z]{2,4}$/ ? "GOOD!!!" : "bad" ; print "\n" ; }

This yelds: is GOOD!!! me@here is bad me@here@there@everywhere is bad why@ is bad is bad

Please remember this is only the simplest case!!!, mail addresses syntax is far more complicated than one would expect reading common addresses. The best way to understand it is to try to write a spam filter for personal use :-)

Have fun!


# Another Perl edition of a song:
# The End, by The Beatles
  $you->take($love) eq $you->made($love) ;

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-17 04:56 GMT
Find Nodes?
    Voting Booth?

    No recent polls found