List:General Discussion« Previous MessageNext Message »
From:fbsd Date:May 20 2006 5:30pm
Subject:RE: Find invalid email formats using MySQL query.
View as plain text  
You need to use a stronger edit to check email addresses.
This is what I use. Note the dns mx domain name check.

$len = "0,45";
if (empty ($email))
     { $errors[] = "<font color=red>You didn't enter a Email
Address.</font>"; }
    elseif (!ereg("^([[:alnum:]\.\_\-]+)(\@[[:alnum:]\.\-]+\.+)",
$email))
       { $errors[] = "<font color=red>Email Address format is
invalid. It must be
         this format name@stripped.</font>";
         $errors[] = "<font color=red>Alpha-Numeric characters
plus - and . and _
          and @ are valid in the address.</font>"; }
      else
        { // good email address so far now check for good dns mx for
domain name
          list($Username, $Domain) = split("@",$email);
          if(!getmxrr($Domain, $MXHost))
             { $errors[] = "<font color=red>Email Address Domain
name is invalid because
               it has no DNS mx records.</font>";}


As far as I know there is no way to do this in a query command. You
have to read every row's email field and then process against the
php code to check/validate followed by a DB delete for all bad ones.

Far better to fix code that edits the email field before adding it
to db.
Denying bad field content before adding it is the normal way this is
done.

-----Original Message-----
From: Yesmin Patwary [mailto:yesmin25@stripped]
Sent: Saturday, May 20, 2006 10:48 AM
To: mysql@stripped
Subject: Find invalid email formats using MySQL query.


Dear All,

  My contact table has email field which contains many invalid email
addresses. I find them using following php function.  Is there a way
to do that check in MySQL query?

  function emailValidate ($str)
 {
    $reg = "^([a-zA-Z0-9._-]+)@([a-zA-Z0-9-])+(\.[a-zA-Z0-9-]+)+$";
    if (eregi($reg, $str)) {
         return true;//-- good email
     }else{
         return false;//--bad email
     }
  }//--close function

  Thanks in advance for any comments or help.


---------------------------------
Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls.
Great rates starting at 1&cent;/min.

Thread
Find invalid email formats using MySQL query.Yesmin Patwary20 May
  • Re: Find invalid email formats using MySQL query.Keith Roberts20 May
  • Re: Find invalid email formats using MySQL query.Peter Brawley20 May
  • RE: Find invalid email formats using MySQL query.fbsd20 May
    • RE: Find invalid email formats using MySQL query.Keith Roberts20 May
      • RE: Find invalid email formats using MySQL query.Chris Sansom21 May