This code is self explainable except that Regular Expression which I used for pattern matching.
I originally published as a thread on my website : http://www.aliencoders.com
First of all we should know the rules and regulation for using email address.
Email could be anything but it should have some boundary like
1. It will have @ and .
2. Username can be a mixture of character, digit and _ (usually) of any length but it should start with only character i.e from a-z or A-Z (I restrcited length from 8-15, yu can put your own).
3. Domain Name should be between 2 to 63
4. after the last . there should not be @ and it could be in range of 2-4 only like
I am checking proper email condition and then checking for email id length which should be between 6 and 15 (ex: jassics@aliencoders.com So, here my email id length is 7 <jassics>)
This line is the important line to understand.
Whatever 4 points I mentioned before writing the code, I just used those rules to write this pattern.
^ means It should start with
[] means range so [a-zA-Z] means any character from a-z or A-Z
\w is for word which includes digits, alphabets . It's a short form in Perl to write for word (more than one character in simpler way)
{} define range
+ means at least one or more
$ means it should end with
() means group, whatever will be coming in this group will be captured by Perl-s inbuilt variable like $1 , $2 etc...
So ^([a-zA-Z][\w\_]{6,15}) means , it should start with any character from a-z or A-Z followed by word and _ and it should be between 6 and 15
\@ as @ meant for array declaration i nperl so we should avoid it by using backslash to get it's normal meaning. Thats why we used \@
I think rest part of the code will be understood as it uses above concepts only
by: ozo on 2012-02-01 at 05:54:37ID: 41449
In particular <fred&barney@stonehenge.co
see
perldoc -q 'How do I check a valid mail address'
for the correct email address standard, and the correct way to do email address validation