Connecting Tech Pros Worldwide Forums | Help | Site Map

ereg question

bigoxygen@gmail.com
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi

I am trying to validate an e-mail address using this expression

[A-Za-z0-9]@[A-Za-z0-9]\.[A-Za-z0-9]

However, the escaped period is causing me a lot of grief.
Please help.


Ewoud Dronkert
Guest
 
Posts: n/a
#2: Jul 17 '05

re: ereg question


On 23 Mar 2005 12:11:43 -0800, bigoxygen@gmail.com wrote:[color=blue]
> I am trying to validate an e-mail address using this expression
> [A-Za-z0-9]@[A-Za-z0-9]\.[A-Za-z0-9]
> However, the escaped period is causing me a lot of grief.[/color]

Try

function is_email( $test )
{
if ( strlen( $test ) < 7 ) return false;
return ( eregi( '^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$', $test )
&& !ereg( '[@._-]{2}', $test ) );
}

...but does not validate umlaut-domains or top level domains like .museum
(longer than 4 chars). Latter is easily corrected if you wish to accept
those addresses.


--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Funnyweb
Guest
 
Posts: n/a
#3: Jul 17 '05

re: ereg question


Try this:

^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$

Hamilton


<bigoxygen@gmail.com> wrote in message
news:1111608702.982322.236600@z14g2000cwz.googlegr oups.com...[color=blue]
> Hi
>
> I am trying to validate an e-mail address using this expression
>
> [A-Za-z0-9]@[A-Za-z0-9]\.[A-Za-z0-9]
>
> However, the escaped period is causing me a lot of grief.
> Please help.
>[/color]


Ewoud Dronkert
Guest
 
Posts: n/a
#4: Jul 17 '05

re: ereg question


On Thu, 24 Mar 2005 09:37:23 +1200, Funnyweb wrote:[color=blue]
> ^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$[/color]

No need for backslashes in char classes. If using - (dash) in char
classes, put it at 1st or last position to avoid its range meaning.
Also, + is allowed in the username part of an e-mail address (omitted in
my code too, I saw).


--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Closed Thread


Similar PHP bytes