SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru DeNasio's Avatar
    Join Date
    May 2001
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Validating e-mail address

    Hello,

    I'm using the following code to validate an e-mail address:

    Code:
    if (eregi("(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\.$)|(\|)",$email) or !eregi("^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$",$email))
       {
       .......
       }
    But the problem is that it does not work! I used to use this exact code in Perl and there it used to work fine.

    Can anyone tell me why it does not work?

  2. #2
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what I use...

    <?php

    $submit=1;

    function check_email ($str) {
    // Returns 1 if a valid email, 0 if not

    if (ereg ("^.+@.+\\..+$", $str)) {
    return 1;
    } else {
    return 0;
    }
    }



    if (!check_email ($email)) {
    $submit=0;
    $email = "Invalid Email address";

    }

    ?>

    This checks the email submitted. If it was OK it returns a 1 and allows them to continue. If not, it says Invalid email address and offers a Back button to go and try again - this is the other code needed...

    <?php

    if ($submit) {

    echo("<INPUT TYPE='submit' VALUE='Send Comments'>");

    }

    echo("<INPUT TYPE='button' VALUE='Go Back' ONCLICK='self.history.back();'>");

    ?>

    Hope this helps...


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
  •