I need a password validation code snippet for my registration form. Here are the rules for the password: - At least one uppercase letter - At least one lowercase letter - At least one number - At least one special character - Only alphanumeric and !@#$%^&*() characters Thanks -812402
Following is code snippet which validate password:  function validatePassword($src) {  $valid = true;  $upper = false;  $lower = false;  $digit = false;  $special = false;  for ($i = 0; $i < strlen($src); $i++) {   $co = ord($src{$i});   if ($co >= ord('A') && $co <= ord('Z')) {    $upper = true;   } else if ($co >= ord('a') && $co <= ord('z')) {    $lower = true;   } else if ($co >= ord('0') && $co <= ord('9')) {    $digit = true;   } else if (strpos("!@#$%^&*()", $src{$i}) != false) {    $special = true;   } else {    $valid = false;   }  }  return $valid && $upper && $lower && $digit && $special; } PHP:
For this code you would need to post the data to a page with this function on it and call it from there. If you are looking to validate prior to submitting the form then you would need to use javascript instead of php.
I am mention regex below.... Assert a string is 8 or more characters: (?=.{8,}) Assert a string contains at least 1 lowercase letter (zero or more characters followed by a lowercase character): (?=.*[a-z]) Assert a string contains at least 1 uppercase letter (zero or more characters followed by an uppercase character): (?=.*[A-Z]) Assert a string contains at least 1 digit: (?=.*[\d]) Assert a string contains at least 1 special character: (?=.*[\W]) Assert a string contains at least 1 special character or a digit: (?=.*[\d\W])