Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Smile Email validation

    Hi,

    Am trying to integrate some code i found at ilovejackdaniels.com into my form processing script.
    Can anyone point out where I'm going wrong.

    PHP Code:
    <?php 
    $email
    =$_POST['visitor_email'];

    // Validate Email Address
    function check_email_address($email) {
    // First, we check that there's one @ symbol, and that the lengths are right
    if (!ereg("^[^@]{1,64}@[^@]{1,255}$"$email)) {
    // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
    return false;
    }
    // Split it into sections to make life easier
    $email_array explode("@"$email);
    $local_array explode("."$email_array[0]);
    for (
    $i 0$i sizeof($local_array); $i++) {
    if (!
    ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$"$local_array[$i])) {
    return 
    false;
    }
    }
    if (!
    ereg("^\[?[0-9\.]+\]?$"$email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
    $domain_array explode("."$email_array[1]);
    if (
    sizeof($domain_array) < 2) {
    return 
    false// Not enough parts to domain
    }
    for (
    $i 0$i sizeof($domain_array); $i++) {
    if (!
    ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$"$domain_array[$i])) {
    return 
    false;
    }
    }
    }
    return 
    true;
    }

    if (
    check_email_address($email)) {
            }
            else{
                
    $error.="Please, go back and check your <strong>Email Address</strong><br><br><a href=\"javascript: history.go(-1)\">< Back</a>\n";//----> ERROR if invalid
                
    }
        
    //-------->ERROR FREE??
        
    if($error==""){

    ?>
    Any help would be much appreciated!
    You think anybody wants a roundhouse kick to the face while I'm wearing these bad boys? Forget about it.
    <!------------o\/o-----------?>

  • #2
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Can anyone point out where I'm going wrong.
    Can you? We need to know what the issue is before we can help.

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Sorry having trouble explaining myself

    I need the code to display an error message if the email address is invalid and stop the process.

    i believe it's this final else statement that's the problem, the error message does not display and the process continues.
    PHP Code:
    else{
                
    $error.="Please, go back and check your <strong>Email Address</strong><br><br><a href=\"javascript: history.go(-1)\">< Back</a>\n";//----> ERROR if invalid
                

    Sorry if this is all seems a bit vague...still quite a noob at this.
    You think anybody wants a roundhouse kick to the face while I'm wearing these bad boys? Forget about it.
    <!------------o\/o-----------?>

  • #4
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,008
    Thanks
    59
    Thanked 10 Times in 10 Posts
    So you input an invalid email and nothing happens?


  • #5
    New Coder
    Join Date
    Jun 2007
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts
    It's ok, have fixed the problem...sorry to have bothered you.

    I Was making it much more complicated than it needed to be, as is always the way the answer was right in front of me all along!

    Thanks again!!
    You think anybody wants a roundhouse kick to the face while I'm wearing these bad boys? Forget about it.
    <!------------o\/o-----------?>

  • #6
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,008
    Thanks
    59
    Thanked 10 Times in 10 Posts
    Please post your valid code so we can learn from it



  •  

    Posting Permissions

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