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,10 +13,7 @@ class FormValidator {
}
foreach($this->fieldValidation as $field => $params) {
if($params['required'] && (!isset($req[$field]) || strlen($req[$field]) == 0)) {
return false;
}
if(isset($req[$field]) && strlen(trim($req[$field])) > 0) {
if(isset($params['regex'])) {
if(!preg_match($params['regex'], $req[$field])) {
return false;
@ -26,6 +23,10 @@ class FormValidator {
return false;
}
}
else if($params['required']) {
return false;
}
}
return true;
}