Jump to content

Validation order


graham23s

Recommended Posts

Hi Guys,

 

in my form validation i currntly have:

 

<?php
  // error checking //
  if(empty($username))
  {
   standard_error("Error","You never entered a username."); 
   $error = TRUE;
  }
  if(empty($pass_1))
  {
   standard_error("Error","You never entered a password."); 
   $error = TRUE;
  }
  if(empty($pass_2))
  {
   standard_error("Error","You never confirmed your password."); 
   $error = TRUE;
  }
  if(empty($email_1))
  {
   standard_error("Error","You never entered an e-mail address."); 
   $error = TRUE;
  }
  if(empty($email_2))
  {
   standard_error("Error","You never confirmed your e-mail address."); 
   $error = TRUE;
  }
  if(empty($zip_post_code))
  {
   standard_error("Error","You never entered your zip/post code."); 
   $error = TRUE;
  }
  if($image_file_size > $maximum_filesize)
  {
   standard_error("Error","Your uploaded image is bigger than <b>3mb</b> please upload another."); 
   $error = TRUE;
  }
  if($file_extension != IMAGETYPE_GIF && $file_extension != IMAGETYPE_JPEG && $file_extension != IMAGETYPE_PNG)
  {
   standard_error("Error","Your uploaded image is not one of these allowed file-types only <b>.jpg</b>/<b>.gif</b> and <b>.png</b> are allowed."); 
   $error = TRUE;
  }
  if($ver_code_1 != $ver_code_2)
  {
   standard_error("Error","Your image verification numbers don't match up."); 
   $error = TRUE;  
  }
  if(!(ereg ("^.+@.+\..+$", $email_1))) {
  {
   standard_error("Error","Your e-mail address looks invalid."); 
   $error = TRUE;  
  }  
?>

 

i'm wondering if my order is correct

 

1) check no fields are empty

2) check image format is allowed

3) check image verification numbers match

4) check e-mail is in a proper format

 

it works but just incase i have missed something or could have done it better.

 

thanks guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/97341-validation-order/
Share on other sites

Or even more.

 

<?php
function IsValidEmailAddress($email){
                $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
                $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
                $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
                        '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
                $quoted_pair = '\\x5c[\\x00-\\x7f]';
                $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
                $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
                $domain_ref = $atom;
                $sub_domain = "($domain_ref|$domain_literal)";
                $word = "($atom|$quoted_string)";
                $domain = "$sub_domain(\\x2e$sub_domain)*";
                $local_part = "$word(\\x2e$word)*";
                $addr_spec = "$local_part\\x40$domain";
                return preg_match("!^$addr_spec$!", $email) ? 1 : 0;
        }
?>

Link to comment
https://forums.phpfreaks.com/topic/97341-validation-order/#findComment-498147
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.