467,882 Members | 1,185 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,882 developers. It's quick & easy.

email validation

Hello, im posting this question because i have zero knowledge on perl. I have a script which curently allows users to input an email address and if the email is not valid it wont allow the submission. Everything works fine except that now there are clients who have a period in their email address and it is rejected. eg. tom.jones@email.com.. im sure its a simple addition to the script not even sure where it might go but here is what i copied and where im assuming it might need to be changed..


Code: ( text )
Expand|Select|Wrap|Line Numbers
  1. # Do our error checking
  2.   my $gintErrorCount = 0;
  3.   my $gstrMessage = "";
  4.  
  5.   # Email Address
  6.   unless ($gstrHash{email} =~ m/^(\w+)\@(\w+)\.(\w{2,4})$/)  {$gintErrorCount ++; $gstrMessage .= "Your email address is not properly formatted.<BR>";}
  7.  
  8.   # Fix phone variable - client
  9.   $gstrHash{cphone} =~ s/\D//g;
  10.   unless ($gstrHash{cphone} =~ m/^\d{10}$/) {$gintErrorCount ++; $gstrMessage .= "Your contact phone number must be a ten digit number.<BR>";}
  11.   $gstrHash{cphone} =~ s/^([\d]{3}?)([\d]{3}?)([\d]{4}?)$/\($1\)$2-$3/i;   
  12.  
  13.   # Email Address
  14.   unless ($gstrHash{cemail} =~ m/^(\w+)\@(\w+)\.(\w{2,4})$/)  {$gintErrorCount ++; $gstrMessage .= "Your contact email address is not properly formatted.<BR>";}
  15.  
i appreciate any help
thanks
EMI
Sep 8 '08 #1
  • viewed: 2189
Share:
4 Replies
numberwhun
Expert Mod 2GB
In that case, you could modify your regex to be something like:

Expand|Select|Wrap|Line Numbers
  1. m/^(\w+\.*\w*)\@(\w+)\.(\w{2,4})$/
  2.  
Mind you, that is totally untested, but in theory, I believe it should work. Test it to find out. The \.*\w* will only match if they are present.

Regards,

Jeff
Sep 8 '08 #2
eWish
Expert 512MB
I would suggest that you use a trusted and proven module called Email::Valid. Is it perfect? No, however it is going to be better than designing your own. Check out the source code and see the regex the author built.

If you want to do you own you could use something like this.
Expand|Select|Wrap|Line Numbers
  1. my $email =~ /^[^@]+@([-\w]+\.)+[A-Za-z]{2,4}$/;
I still suggest Email::Valid.

--Kevin
Sep 8 '08 #3
thank you guys...i think that did it..just have to try a few tests live and see how it goes.
much appreciated.
Cheers
Emi
Sep 10 '08 #4
eWish
Expert 512MB
What did you end up using?

--Kevin
Sep 10 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

25 posts views Thread by Dynamo | last post: by
4 posts views Thread by VbUser25 | last post: by
2 posts views Thread by Tim Mills | last post: by
35 posts views Thread by Mika M | last post: by
11 posts views Thread by Bob Bedford | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.