Simple email validation
5
Simple function to check for a valid email address. Makes sure the @ and a . are in the right place. There is most likely a perl package on CPAN that would be more extensive, but this happens to work for my uses.



me
jamesmcm
Can
Kelmi
ysg
dannymo2
chorny
wallie
Hackdemian
impomatic
dannyboy
sundaramkumar
mattrmiller
Pio
i_kenneth
ASmith
ctiggerf
sehrgut
bertheymans
SCoon
Also, you have the host and sub host separation parsing good, but the local name parsing allows an infinite number of periods in a row.
-CB
# Somewhat better validation
$email =~ /^[\w\+-]+(\.[\w\+-]+)*@[\w-]+(\.[\w-]+)*\.\w{2,4}$/;
# Much better validation per RFC 822 & RFC 2822
$email =~ /^[\w,!#$%&'*+\/=?^`{|}~-]+(\.[w,!#$%&'*+\/=?^`{|}~-]+)*@[\w-]+(\.[\w-]+)*\.[\w]{2,}$/;
# You could also allow for the standardized maximum lengths...
---
Sasha Chorny, http://chorny.net