On Wednesday 23 June 2004 09:29 pm, LRMK wrote:
> I am using following code to validate e-mail addresses
>
> if ($mail =~ m/^(\w+(\.|-))*\w+\@(\w+(\.|-)*)+\w+$/){
>         valid
> }else{
>     invalid
> }
>
> it will give valid results for all of the following e-mail address
>
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
>
>
> ...
>
> but I am not sure about the illegal chars for an e-mail address
> can someone check above code tell me whether this matches all the valid
> e-maill
> address and only the valid e-mail addresses.

You best reference for valid characters in the e-mail
address is RFC 822 which you can find via google or at:

http://www.faqs.org/rfcs/rfc822.html

It's rather heavy reading, but it's the standard.
I use this regex:

$valid = $addr =~ m#[\w\/\?\:\&\=\+\$\|\,\-\.\!\~\*\'\(\)[EMAIL PROTECTED];

which is a closer approximation to the RFC than your tests.
It is prob not restrictive enough, but I use it only to
format my web pages with an email address href.

You should check CPAN also.

Aloha => Beau;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to