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: address@some.domain.here
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(you@somewhere.com
me@here
me@here@there@everywhere
why@
@.it) ;
foreach (@addresses) {
print "$_ is " ;
print /^\S+\@([a-z-]+\.)+[a-z]{2,4}$/ ? "GOOD!!!" : "bad" ;
print "\n" ;
}
This yelds:
you@somewhere.com is GOOD!!!
me@here is bad
me@here@there@everywhere is bad
why@ is bad
@.it 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!
Ciao! --bronto
# Another Perl edition of a song:
# The End, by The Beatles
END {
$you->take($love) eq $you->made($love) ;
}
|