SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru
    Join Date
    Oct 2001
    Location
    USA
    Posts
    764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Invalid email address

    How could I remove all the invalid email address from my mysql databse? ie ME.hotmails.com or thisguyyahoo.com or thisguy@yahoocom

  2. #2
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll want to select all applicable records, loop through them and check for validity. When you find an invalid one, store its ID. After you've gone through all of them, do a DELETE query on all the IDs you stored.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  3. #3
    SitePoint Guru
    Join Date
    Oct 2001
    Location
    USA
    Posts
    764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right. But how do I do that. What would be the php coding.

    Also once that is done how can I stop people from entering invalid email addys? What snipet would I add to my existing php newsletter gathering form to make sure the email was a valid one?

  4. #4
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do it 2 ways:

    via JS:
    Put the following in emailcheck.js
    function emailCheck (emailStr)
    {
    var emailPat=/^(.+)@(.+)$/
    var specialChars="\\(\\)<>&#064;,;:\\\\\\\"\\.\\[\\]"
    var validChars="\[^\\s" + specialChars + "\]"
    var quotedUser="(\"[^\"]*\")"
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
    var atom=validChars + '+'
    var word="(" + atom + "|" + quotedUser + ")"
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
    var matchArray=emailStr.match(emailPat)
    if (matchArray==null)
    return false
    var user=matchArray[1]
    var domain=matchArray[2]
    if (user.match(userPat)==null)
    {
    alert("The username doesn't seem to be valid.")
    return false
    }
    var IPArray=domain.match(ipDomainPat)
    if (IPArray!=null)
    {
    for (var i=1;i<=4;i++)
    {
    if (IPArray[i]>255)
    return false
    }
    return true
    }
    var domainArray=domain.match(domainPat)
    if (domainArray==null)
    return false
    var atomPat=new RegExp(atom,"g")
    var domArr=domain.match(atomPat)
    var len=domArr.length
    if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>4)
    return false
    if (len<2)
    return false
    return true;
    }
    and for your form <form [other tags here] onSubmit="emailcheck.js"> , i tihnk.

    Via php,

    here's a quickie.
    PHP Code:
    <?php
    function validate($addy) {
        if (
    preg_match("/^([A-Z0-9\.\-_]+)@([A-Z0-9\.\-_]+)?([\.]{1})([A-Z0-9\-_]{2,6})$/i"$addy$matches)) {
            return 
    1;
        } else {
            return 
    0;
        }
    }
    //script in action below
    $addy "sh@aaa.com";
    if (
    validate($addy) == 0) { //function returns 0 if email addy is not valid
       
    echo "Not valid"
    } else {
       echo 
    "Valid";
    }
    ?>

  5. #5
    SitePoint Guru
    Join Date
    Oct 2001
    Location
    USA
    Posts
    764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to use the PHP version, butI'm not sure how this is suppose to work. My form brings in the email addy as $email

    Part of your code that confuses me is the part where you have an email address entered into the script 'sh@aaa.com'???

  6. #6
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sh@aaa.com was just a dummy email address to check the function.

    scrap this line : $addy = sh@aaa.com;

    and replace $addy with $email

    You can leave the function untouched.

  7. #7
    SitePoint Guru
    Join Date
    Oct 2001
    Location
    USA
    Posts
    764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That works awesome. Thank You.

    Now how do I get rid of the ones I already have?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •