Connecting Tech Pros Worldwide Help | Site Map

ereg question

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 12:15 PM
bigoxygen@gmail.com
Guest
 
Posts: n/a
Default ereg question

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, 12:15 PM
Ewoud Dronkert
Guest
 
Posts: n/a
Default 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, 12:15 PM
Funnyweb
Guest
 
Posts: n/a
Default 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, 12:15 PM
Ewoud Dronkert
Guest
 
Posts: n/a
Default 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/
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.