1
0
Fork 0
Manager/classen/FormValidator.php

30 lines
766 B
PHP
Raw Normal View History

2023-08-23 16:16:34 +00:00
<?php
class FormValidator {
private array $fieldValidation;
public function __construct(array $fieldValidation) {
$this->fieldValidation = $fieldValidation;
}
public function isValid(array $req) {
foreach($fieldValidation as $field => $params) {
if($params['required'] && (!isset($req[$field]) || strlen($req[$field]) == 0)) {
2023-08-23 16:16:34 +00:00
return false;
}
if(isset($params['regex'])) {
if(!preg_match($params['regex'], $req[$field])) {
return false;
}
}
else if(isset($params['equals']) && $params['equals'] !== $req[$field]) {
2023-08-23 16:16:34 +00:00
return false;
}
}
return true;
}
}
?>