Jump to content

Logic Issue? Email validation


ahphpnz

Recommended Posts

Hey all, trying to figure out a logic flaw in this validation script. Basically if I use !preg_match or the preg_match examples (noted below), I do not get the correct results.

 

My interpretation of preg_match and my current understanding of the logic is noted below (please correct me if I'm wrong).

 1. If I use alternate attempt !preg_match, the regex would be compared against the "string" in the $email variable. If the regex expression matches, error will be thrown and script would stop.

 2. If I use alternate attempt !preg_match, the condition would be not true and move to else where the string contained within $email variable would be run through the vld function.

 3. If I maintain the current script using preg_match, if the string matches the match, the condition would be true and therefore string of $email variable runs through VLD function else cleanup and throw error...

 

Are my statements above correct in this context? I think I'm pretty close to cracking it but seem to be missing something simple.

 

The current script is referenced below, forgive me if I've lost the plot. Long hours attempting to understand this language, from what I've seen so far its great.

 

Thanks in advance,

A

 

 

//Alternate attempt

  if (!preg_match("/^[^@]+@[^@.]+\.[^@]*\w\w/", $email)) {
                                    $error = "Please enter a valid email address"; } else {

                                    $email = vld($_POST['email']);
                                  }

 

Current code that doens't work:

 

if (empty($_POST['email'])) {
    $error = "Email is required"; } else {
       if (strlen($_POST['email']) < 5) {
           $error = "Email is too short!"; } else {
              if (strlen($_POST['email']) > 30) {
                  $error = "Email is too long!"; } else {
                      if (preg_match("/[\(\)\<\>\,\;\:\\\"\[\]]/", $email)) {
                          $error = "The email address contains illegal characters"; } else {
                              if (preg_match("/^[^@]+@[^@.]+\.[^@]*\w\w/", $email)) {
                                  $email = vld($_POST['email']); } else {
                                      $error = "Please enter a valid email address";
                                  }
                         }
                  }
           }
    }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.