1
0
Fork 0

Only check regex and equals when field is provided

master
Anonymous Contributor 2023-08-23 18:16:35 +02:00
parent d70fd4357a
commit 4d20b7e2f3
1 changed files with 8 additions and 7 deletions

View File

@ -13,16 +13,17 @@ class FormValidator {
}
foreach($this->fieldValidation as $field => $params) {
if($params['required'] && (!isset($req[$field]) || strlen($req[$field]) == 0)) {
return false;
}
if(isset($params['regex'])) {
if(!preg_match($params['regex'], $req[$field])) {
if(isset($req[$field]) && strlen(trim($req[$field])) > 0) {
if(isset($params['regex'])) {
if(!preg_match($params['regex'], $req[$field])) {
return false;
}
}
else if(isset($params['equals']) && $params['equals'] !== $req[$field]) {
return false;
}
}
else if(isset($params['equals']) && $params['equals'] !== $req[$field]) {
else if($params['required']) {
return false;
}
}