Jumping in...

On Tue, 11 Mar 2003 20:19:36 -0500 (PET), David E.S.V. wrote about "Re:
[PHP] Checking for a Valid Email String." what the universal translator
turned into this:

>you mean something like this?
>
>//checking if the email is valid
>
>if 
>(eregi("^[0-9a-z]([-_.]?[0-9a-z])[EMAIL PROTECTED]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", 
>$email, $check))
> {
>  if ( !getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp) )
>    $mensaje="server not valid";
>  
>
>  // checking DNS
>  if(!checkdnsrr(substr(strstr($check[0], '@'), 1),"ANY"))
>     $mensaje="server not valid";
> 
> }

Now I haven't really checked up on ereg ... but besides I don't check with
DNS, can anyone tell me if my version (below), actually checks for all
possible invalids (I know I'm missing high-bit char tests)...

  function ValidEmail($email) {
  // function for verification of e-mail address
  // needs modification to test for high-bit chars
    $invalidChars = array(" ","/",":",",",";");
    if ($email == "") {
      return false;
    }
    for ($n = 0; $n < count($invalidChars); $n++) {
      if (strpos($email,$invalidChars[$n]) != false) {
        return false;
      }
    }
    $atPos = strpos($email,"@",1);
    if ($atPos === false) {
      return false;
    }
    if (strpos($email,"@",$atPos + 1) != false) {
      return false;
    }
    $dotPos = strpos($email,".",$atPos);
    if ($dotPos === false) {
      return false;
    }
    if ($dotPos + 3 > strlen($email)) {
      return false;
    }
    return true;
  }

I created this a few months ago by converting a JS script, and haven't
really looked at it since. It works mostly like intended, but could
probably need some tweaking. It checks for all non-accepted chars, double
@s, and impossible dot-positions. It doesn't check for high-bit chars, and
doesn't actually verify the address. It's for subbing to my maillist, so
the mailserver actually does the verification itself.

Any comments ??? Or suggestions ???

Rene

-- 
Rene Brehmer

This message was written on 100% recycled spam.

Come see! My brand new site is now online!
http://www.metalbunny.net

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

Reply via email to