SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Checking multiple inserts if valid email!

    I want to be able to check my form inputs (max 4) if they all have a valid email inserted before going to insert into my db table, but not sure how to do so...

    This is my script so far, but doesnt seem to work?
    PHP Code:
    for ($i 0$i count($firstname); $i++) {
                
                    
    $nemail $email[$i];
                    
                    echo 
    ''.$firstname[$i].' '.$lastname[$i].' ( '.$nemail.' )<br>';
                    
                    if (
    eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]"$nemail)) 
                    {
                       echo 
    'Email OK<br><br>';
                    } else {
                        echo 
    'No Email...<br><br>';
                    }
                        
                        
            } 
    When going thruogh this I get "No Email..." even if a field is blank or has no @ in it...

    Please help :-)

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jmansa View Post
    When going thruogh this I get "No Email..." even if a field is blank or has no @ in it...

    Please help :-)
    Isn't this the expected output? It says "No Email" if the address is not valid, and a blank is not a valid e-mail.

  3. #3
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But it also says "No Email..." if the address is correct?

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $valid true;
    for (
    $i 0$i count($firstname); $i++) { 
        if (!
    eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]"$email[$i]))
            
    $valid false;
    }

    if (
    $valid) {
      echo 
    "All e-mails are OK";
    } else {
      echo 
    "One or more e-mails are not OK";


  5. #5
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    PHP Code:
    $valid true;
    for (
    $i 0$i count($firstname); $i++) { 
        if (!
    eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]"$email[$i]))
            
    $valid false;
    }

    if (
    $valid) {
      echo 
    "All e-mails are OK";
    } else {
      echo 
    "One or more e-mails are not OK";

    If I insert email addresses I still get the "One or more e-mails are not OK"? And what if one field is not filled...

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    How about sharing the form we're coding against? And are you sure the regular expression is correct, you've tested it against a single e-mail address? I don't know what the last bracket is there for, and it seems to be missing the delimiters around the whole thing.

  7. #7
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the form part...

    PHP Code:
    echo '<table><tr>
                                    <td align="right"><div align="right"><h3>First Name:</h3></td>
                                    <td><input name="fname[]" type="text" size="30"> '
    .$err_firstname0.'</td>
                                </tr>
                                <tr>
                                    <td align="right"><div align="right"><h3>Last Name(s):</h3></td>
                                    <td><input name="lname[]" type="text" size="30"></td>
                                </tr>
                                <tr>
                                    <td align="right"><div align="right"><h3>E-mail:</h3></td>
                                    <td><input name="email[]" type="text" size="30"></td>
                                </tr>
                                <tr>
                                    <td colspan="2"><br><div style="border-bottom:1px solid #669900;"></div><br></td>
                                </tr>
                                <tr>
                                    <td align="right"><div align="right"><h3>First Name:</h3></td>
                                    <td><input name="fname[]" type="text" size="30"></td>
                                </tr>
                                <tr>
                                    <td align="right"><div align="right"><h3>Last Name(s):</h3></td>
                                    <td><input name="lname[]" type="text" size="30"></td>
                                </tr>
                                <tr>
                                    <td align="right"><div align="right"><h3>E-mail:</h3></td>
                                    <td><input name="email[]" type="text" size="30"></td>
                                </tr>
                                <tr>
                                    <td colspan="2"></td>
                                </tr>
                                <tr>
                                    <td colspan="2"><br><div style="border-bottom:1px solid #669900;"></div><br></td>
                                </tr>
                                <tr>
                                    <td align="right"><div align="right"><h3>First Name:</h3></td>
                                    <td><input name="fname[]" type="text" size="30"></td>
                                </tr>
                                <tr>
                                    <td align="right"><div align="right"><h3>Last Name(s):</h3></td>
                                    <td><input name="lname[]" type="text" size="30"></td>
                                </tr>
                                <tr>
                                    <td align="right"><div align="right"><h3>E-mail:</h3></td>
                                    <td><input name="email[]" type="text" size="30"></td>
                                </tr>
                                <tr>
                                    <td colspan="2"></td>
                                </tr>
                                <tr>
                                    <td colspan="2"><br><div style="border-bottom:1px solid #669900;"></div><br></td>
                                </tr>
                                <tr>
                                    <td align="right"><div align="right"><h3>First Name:</h3></td>
                                    <td><input name="fname[]" type="text" size="30"></td>
                                </tr>
                                <tr>
                                    <td align="right"><div align="right"><h3>Last Name(s):</h3></td>
                                    <td><input name="lname[]" type="text" size="30"></td>
                                </tr>
                                <tr>
                                    <td align="right"><div align="right"><h3>E-mail:</h3></td>
                                    <td><input name="email[]" type="text" size="30"></td>
                                </tr>
                                <tr>
                                    <td colspan="2"></td>
                                </tr>
                            </table>'



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
  •