Friday, 13 September 2013

Pregmatch not matching correctly in php

Pregmatch not matching correctly in php

Having trouble understanding what's going on here. Comments within the
code explain. Thanks in advance. To make it easier to read some code bits
are missing like the writing to the DB part. But the problem is isolated
to these lines.
if (filter_var($email, FILTER_VALIDATE_EMAIL) == TRUE and
preg_match("/^[\w ]+$/", $address_one) == TRUE and
preg_match("((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{8,20})",
$password) == TRUE) {
//When given a valid email/address/password the code successfully gets to
this point and inserts into a DB
} else {
//When it fails validation with an invalid email/password/address it
drops in here
//but then it doesn't change error code variable...
$errorcode = "IHAVENOTCHANGED";
if (filter_var($email, FILTER_VALIDATE_EMAIL) == FALSE) {
$errcode = " email,";
}
if (preg_match("/^[\w ]+$/", $address_one) == FALSE) {
$errcode = " address line 1,";
}
if (preg_match("((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{8,20})",
$password) == FALSE) {
$errcode = " password,";
}
writetolog("LoginCreation", "Login failed due to invalid input: " .
$errorcode . " - user: " . $email);
echo "Invalid data for $errorcode please try again --
ADDRESS=$address_one -- EMAIL=$email -- PASS=$password";
}

No comments:

Post a Comment