Help with email validation string

B

Bill H

I have been using the following small routine to validate that an email
address is properly formatted and it works good with most email
addresses, but if the email address has more than 3 letters in the tld
(ie .info vs .com) it fails. Can someone tell me how to modify this to
make it work for more than 3 letters in the tld?

sub check_email
{
$email = $_[0];
if ($email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ || $email !~
/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)
{
return 0;
}
else
{
return 1;
}
}

Thank you,

Bill H

P.S. I did not write this routine
 
J

Josef Moellers

Bill said:
I have been using the following small routine to validate that an email
address is properly formatted and it works good with most email
addresses, but if the email address has more than 3 letters in the tld
(ie .info vs .com) it fails. Can someone tell me how to modify this to
make it work for more than 3 letters in the tld?

sub check_email
{
$email = $_[0];
if ($email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ || $email !~
/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)
{
return 0;
}
else
{
return 1;
}
}
Try changing the "2,3" to "2,4" iin the second re to extend the range to
4 letters.
P.S. I did not write this routine

I don't understand it either B-{)
 
P

Paul Lalli

Bill said:
I have been using the following small routine to validate that an email
address is properly formatted

A "small" routine cannot validate that an email address is properly
formatted.
and it works good with most email
addresses,

So people an address that doesn't conform to the one you specify should
be disallowed from using whatever service you're writing?
P.S. I did not write this routine

So why not use another subroutine you didn't write, that actually does
the job correctly?

http://search.cpan.org/~maurice/Email-Valid-0.15/Valid.pm

Paul Lalli
 
B

Bill H

Josef said:
Bill said:
I have been using the following small routine to validate that an email
address is properly formatted and it works good with most email
addresses, but if the email address has more than 3 letters in the tld
(ie .info vs .com) it fails. Can someone tell me how to modify this to
make it work for more than 3 letters in the tld?

sub check_email
{
$email = $_[0];
if ($email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ || $email !~
/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)
{
return 0;
}
else
{
return 1;
}
}
Try changing the "2,3" to "2,4" iin the second re to extend the range to
4 letters.

Thanks Josef - That worked fine.

Bill H
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top