Re: RES: email address syntax checker

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 21 January 2011 11:38, ash@xxxxxxxxxxxxxxxxxxxx
<ash@xxxxxxxxxxxxxxxxxxxx> wrote:
> That won't accept dozens of different types of email addresses. It won't even match some value domains.
>
> Valid email addresses can contain virtually any character in the local part (although in the main they will require being inside quotation marks), and the @ symbol is included in that!
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
> ----- Reply message -----
> From: "Alejandro Michelin Salomon" <amichelins@xxxxxxxxxxx>
> Date: Fri, Jan 21, 2011 12:14
> Subject: RES:  email address syntax checker
> To: "'Donovan Brooke'" <lists@xxxxxxx>
> Cc: <php-general@xxxxxxxxxxxxx>
>
>
>
> Donovan:
>
> Try this
>
> function EmailCheck ( $sEmail )
> Â{
>
> $regexp="/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z
> ]{2,}$/i";
>
> Â Â if ( !preg_match($regexp, $sEmail) )
> Â Â Â Âreturn false;
>
> Â Â return true;
> Â}
>
> Alejandro M.S.
> -----Mensagem original-----
> De: Donovan Brooke [mailto:lists@xxxxxxx]
> Enviada em: quinta-feira, 20 de janeiro de 2011 01:14
> Para: php-general@xxxxxxxxxxxxx
> Assunto:  email address syntax checker
>
> Hi Guys,
>
> I'm waddling my way through database interaction and thought someone on
> the list may already have a simple email checker that they'd like to
> share...
>
> you know, looking for the @ char and dots etc..
>
> I did a quick search of the archives and found a couple elaborate
> things.. but
> I'm looking for something simple. This job will have trusted users and
> the checker is more to help them catch mistakes when registering.
>
> Thanks!,
> Donovan
>
>
> --
> D Brooke
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

http://www.regular-expressions.info/email.html makes a good argument
about the futility of using JUST one massive regex to validate email
addresses.

The long and short of it is the standard says that this should work ...

(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

Which is ...



(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

Which (using RegexBuddy) is explained as ...

Options: case insensitive; ^ and $ match at line breaks

Match the regular expression below
Â(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")Â
   Match either the regular expression below (attempting the next
alternative only if this one fails)
Â[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*Â
      Match a single character present in the list below
Â[a-z0-9!#$%&'*+/=?^_`{|}~-]+Â
         Between one and unlimited times, as many times as possible,
giving back as needed (greedy) Â+Â
         A character in the range between âaâ and âzâ Âa-zÂ
         A character in the range between â0â and â9â Â0-9Â
         One of the characters â!#$%&'*+/=?^_`{|}â Â!#$%&'*+/=?^_`{|}Â
         The character â~â Â~Â
         The character â-â Â-Â
      Match the regular expression below Â(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*Â
         Between zero and unlimited times, as many times as possible,
giving back as needed (greedy) Â*Â
         Match the character â.â literally Â\.Â
         Match a single character present in the list below
Â[a-z0-9!#$%&'*+/=?^_`{|}~-]+Â
            Between one and unlimited times, as many times as
possible, giving back as needed (greedy) Â+Â
            A character in the range between âaâ and âzâ Âa-zÂ
            A character in the range between â0â and â9â Â0-9Â
            One of the characters â!#$%&'*+/=?^_`{|}â Â!#$%&'*+/=?^_`{|}Â
            The character â~â Â~Â
            The character â-â Â-Â
   Or match regular expression number 2 below (the entire group fails
if this one fails to match)
Â"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*"Â
      Match the character â"â literally Â"Â
      Match the regular expression below
Â(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*Â
         Between zero and unlimited times, as many times as possible,
giving back as needed (greedy) Â*Â
         Match either the regular expression below (attempting the
next alternative only if this one fails)
Â[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]Â
            Match a single character present in the list below
Â[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]Â
               A character in the range between ASCII character 0x01
(1 decimal) and ASCII character 0x08 (8 decimal) Â\x01-\x08Â
               ASCII character 0x0b (11 decimal) Â\x0bÂ
               ASCII character 0x0c (12 decimal) Â\x0cÂ
               A character in the range between ASCII character 0x0e
(14 decimal) and ASCII character 0x1f (31 decimal) Â\x0e-\x1fÂ
               ASCII character 0x21 (33 decimal) Â\x21Â
               A character in the range between ASCII character 0x23
(35 decimal) and ASCII character 0x5b (91 decimal) Â\x23-\x5bÂ
               A character in the range between ASCII character 0x5d
(93 decimal) and ASCII character 0x7f (127 decimal) Â\x5d-\x7fÂ
         Or match regular expression number 2 below (the entire group
fails if this one fails to match) Â\\[\x01-\x09\x0b\x0c\x0e-\x7f]Â
            Match the character â\â literally Â\\Â
            Match a single character present in the list below
Â[\x01-\x09\x0b\x0c\x0e-\x7f]Â
               A character in the range between ASCII character 0x01
(1 decimal) and ASCII character 0x09 (9 decimal) Â\x01-\x09Â
               ASCII character 0x0b (11 decimal) Â\x0bÂ
               ASCII character 0x0c (12 decimal) Â\x0cÂ
               A character in the range between ASCII character 0x0e
(14 decimal) and ASCII character 0x7f (127 decimal) Â\x0e-\x7fÂ
      Match the character â"â literally Â"Â
Match the character â@â literally Â@Â
Match the regular expression below
Â(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])Â
   Match either the regular expression below (attempting the next
alternative only if this one fails)
Â(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?Â
      Match the regular expression below
Â(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+Â
         Between one and unlimited times, as many times as possible,
giving back as needed (greedy) Â+Â
         Match a single character present in the list below Â[a-z0-9]Â
            A character in the range between âaâ and âzâ Âa-zÂ
            A character in the range between â0â and â9â Â0-9Â
         Match the regular expression below Â(?:[a-z0-9-]*[a-z0-9])?Â
            Between zero and one times, as many times as possible,
giving back as needed (greedy) Â?Â
            Match a single character present in the list below Â[a-z0-9-]*Â
               Between zero and unlimited times, as many times as
possible, giving back as needed (greedy) Â*Â
               A character in the range between âaâ and âzâ Âa-zÂ
               A character in the range between â0â and â9â Â0-9Â
               The character â-â Â-Â
            Match a single character present in the list below Â[a-z0-9]Â
               A character in the range between âaâ and âzâ Âa-zÂ
               A character in the range between â0â and â9â Â0-9Â
         Match the character â.â literally Â\.Â
      Match a single character present in the list below Â[a-z0-9]Â
         A character in the range between âaâ and âzâ Âa-zÂ
         A character in the range between â0â and â9â Â0-9Â
      Match the regular expression below Â(?:[a-z0-9-]*[a-z0-9])?Â
         Between zero and one times, as many times as possible, giving
back as needed (greedy) Â?Â
         Match a single character present in the list below Â[a-z0-9-]*Â
            Between zero and unlimited times, as many times as
possible, giving back as needed (greedy) Â*Â
            A character in the range between âaâ and âzâ Âa-zÂ
            A character in the range between â0â and â9â Â0-9Â
            The character â-â Â-Â
         Match a single character present in the list below Â[a-z0-9]Â
            A character in the range between âaâ and âzâ Âa-zÂ
            A character in the range between â0â and â9â Â0-9Â
   Or match regular expression number 2 below (the entire group fails
if this one fails to match)
Â\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]Â
      Match the character â[â literally Â\[Â
      Match the regular expression below
Â(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}Â
         Exactly 3 times Â{3}Â
         Match the regular expression below
Â(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)Â
            Match either the regular expression below (attempting the
next alternative only if this one fails) Â25[0-5]Â
               Match the characters â25â literally Â25Â
               Match a single character in the range between â0â and â5â Â[0-5]Â
            Or match regular expression number 2 below (attempting the
next alternative only if this one fails) Â2[0-4][0-9]Â
               Match the character â2â literally Â2Â
               Match a single character in the range between â0â and â4â Â[0-4]Â
               Match a single character in the range between â0â and â9â Â[0-9]Â
            Or match regular expression number 3 below (the entire
group fails if this one fails to match) Â[01]?[0-9][0-9]?Â
               Match a single character present in the list â01â Â[01]?Â
                  Between zero and one times, as many times as
possible, giving back as needed (greedy) Â?Â
               Match a single character in the range between â0â and â9â Â[0-9]Â
               Match a single character in the range between â0â and
â9â Â[0-9]?Â
                  Between zero and one times, as many times as
possible, giving back as needed (greedy) Â?Â
         Match the character â.â literally Â\.Â
      Match the regular expression below
Â(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)Â
         Match either the regular expression below (attempting the
next alternative only if this one fails) Â25[0-5]Â
            Match the characters â25â literally Â25Â
            Match a single character in the range between â0â and â5â Â[0-5]Â
         Or match regular expression number 2 below (attempting the
next alternative only if this one fails) Â2[0-4][0-9]Â
            Match the character â2â literally Â2Â
            Match a single character in the range between â0â and â4â Â[0-4]Â
            Match a single character in the range between â0â and â9â Â[0-9]Â
         Or match regular expression number 3 below (attempting the
next alternative only if this one fails) Â[01]?[0-9][0-9]?Â
            Match a single character present in the list â01â Â[01]?Â
               Between zero and one times, as many times as possible,
giving back as needed (greedy) Â?Â
            Match a single character in the range between â0â and â9â Â[0-9]Â
            Match a single character in the range between â0â and â9â Â[0-9]?Â
               Between zero and one times, as many times as possible,
giving back as needed (greedy) Â?Â
         Or match regular expression number 4 below (the entire group
fails if this one fails to match)
Â[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+Â
            Match a single character present in the list below Â[a-z0-9-]*Â
               Between zero and unlimited times, as many times as
possible, giving back as needed (greedy) Â*Â
               A character in the range between âaâ and âzâ Âa-zÂ
               A character in the range between â0â and â9â Â0-9Â
               The character â-â Â-Â
            Match a single character present in the list below Â[a-z0-9]Â
               A character in the range between âaâ and âzâ Âa-zÂ
               A character in the range between â0â and â9â Â0-9Â
            Match the character â:â literally Â:Â
            Match the regular expression below
Â(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+Â
               Between one and unlimited times, as many times as
possible, giving back as needed (greedy) Â+Â
               Match either the regular expression below (attempting
the next alternative only if this one fails)
Â[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]Â
                  Match a single character present in the list below
Â[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]Â
                     A character in the range between ASCII character
0x01 (1 decimal) and ASCII character 0x08 (8 decimal) Â\x01-\x08Â
                     ASCII character 0x0b (11 decimal) Â\x0bÂ
                     ASCII character 0x0c (12 decimal) Â\x0cÂ
                     A character in the range between ASCII character
0x0e (14 decimal) and ASCII character 0x1f (31 decimal) Â\x0e-\x1fÂ
                     A character in the range between ASCII character
0x21 (33 decimal) and ASCII character 0x5a (90 decimal) Â\x21-\x5aÂ
                     A character in the range between ASCII character
0x53 (83 decimal) and ASCII character 0x7f (127 decimal) Â\x53-\x7fÂ
               Or match regular expression number 2 below (the entire
group fails if this one fails to match)
Â\\[\x01-\x09\x0b\x0c\x0e-\x7f]Â
                  Match the character â\â literally Â\\Â
                  Match a single character present in the list below
Â[\x01-\x09\x0b\x0c\x0e-\x7f]Â
                     A character in the range between ASCII character
0x01 (1 decimal) and ASCII character 0x09 (9 decimal) Â\x01-\x09Â
                     ASCII character 0x0b (11 decimal) Â\x0bÂ
                     ASCII character 0x0c (12 decimal) Â\x0cÂ
                     A character in the range between ASCII character
0x0e (14 decimal) and ASCII character 0x7f (127 decimal) Â\x0e-\x7fÂ
      Match the character â]â literally Â\]Â


But really?


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux