Connecting Tech Pros Worldwide Help | Site Map

ereg question

  #1  
Old July 17th, 2005, 01:15 PM
bigoxygen@gmail.com
Guest
 
Posts: n/a
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.

  #2  
Old July 17th, 2005, 01:15 PM
Ewoud Dronkert
Guest
 
Posts: n/a

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/
  #3  
Old July 17th, 2005, 01:15 PM
Funnyweb
Guest
 
Posts: n/a

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]


  #4  
Old July 17th, 2005, 01:15 PM
Ewoud Dronkert
Guest
 
Posts: n/a

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 Threads
Thread Thread Starter Forum Replies Last Post
ereg question monomaniac21 answers 3 January 28th, 2007 02:15 AM
Easy ereg() question news@celticbear.com answers 3 September 18th, 2005 12:45 AM
ereg question Rafal Zak answers 3 July 17th, 2005 10:16 AM
Ereg question bonehead answers 5 July 17th, 2005 02:31 AM