ereg question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bigoxygen@gmail.com

    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.

  • Ewoud Dronkert

    #2
    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/

    Comment

    • Funnyweb

      #3
      Re: ereg question

      Try this:

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

      Hamilton


      <bigoxygen@gmai l.com> wrote in message
      news:1111608702 .982322.236600@ z14g2000cwz.goo glegroups.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]


      Comment

      • Ewoud Dronkert

        #4
        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/

        Comment

        Working...