#1
  1. No Profile Picture
    tbonds
    Guest
    Devshed Newbie (0 - 499 posts)
    I'm using the below line of code in my program to check if an email address found in a FORM value is valid, yet addresses like ^someth&ing@stuff.com^ are getting through the check OK. Why might the below not be working the way I expect? I thought my code only allows "word" characters since I'm using "/w" in my pattern. Am I missing something here?
    ============================================
    if ( $FORM{'Email'} !~ /[w-]+@[w-]+.[w-]+/ ) {
    do something;
    }
    ====================================

    Thanks in advance.

    -tbonds
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Posts
    0
    Rep Power
    0
    Forget it, even the Perl Cookbook says that there is no viable solution to this problem.
  4. #3
  5. No Profile Picture
    tbonds
    Guest
    Devshed Newbie (0 - 499 posts)
    Maybe I can just use a for-loop and check each character for validity, besides checking something similar to ".*@*.*" for proper email construction.

    If that's what it takes, then so be it.

    -tbonds

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Posts
    452
    Rep Power
    14
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    sub ValidateEmail
    { # Initialize local email variable with input to subroutine. #
    local $email = $_[0];

    # If the e-mail address contains: #
    if ($email =~ /(@.*@)|(..)|(@.)|(.@)|(^.)/ &#0124; &#0124;

    # the e-mail address contains an invalid syntax. Or, if the #
    # syntax does not match the following regular expression pattern #
    # it fails basic syntax verification. #

    $email !~ /^.+@([?)[a-zA-Z0-9-.]+.([a-zA-Z]{2,3}|[0-9]{1,3})(]?)$/) {

    # Basic syntax requires: one or more characters before the @ sign, #
    # followed by an optional '[', then any number of letters, numbers, #
    # dashes or periods (valid domain/IP characters) ending in a period #
    # and then 2 or 3 letters (for domain suffixes) or 1 to 3 numbers #
    # (for IP addresses). An ending bracket is also allowed as it is #
    # valid syntax to have an email address like: user@[255.255.255.0] #

    # Return a false value, since the e-mail address did not pass valid #
    # syntax. #
    return 0;
    }

    else {

    # Return a true value, e-mail verification passed. #
    return 1;
    }
    }

    [/code]
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Posts
    0
    Rep Power
    0
    Instead of doing that, how about you make the user enter the valid address, a confirmation e-mail will be sent, if the user replies, then all is good and do what you want to do, if not then oh well, the user will be not signed up for whatever you are doing. This is the best approach.
  10. #6
  11. No Profile Picture
    tbonds
    Guest
    Devshed Newbie (0 - 499 posts)
    I agree.

    I'm actually developing a shopping cart program that, among other things, emails the customer back all pertinent info regarding his order. Since most people can be careless at least some of the time, I'm adding a simple check for email validity. It won't be foolproof, but it should capture most gross mistakes.

    Regards,
    tbonds

IMN logo majestic logo threadwatch logo seochat tools logo