1
0
Fork 0

Add basic input validation class

master
Anonymous Contributor 2023-08-23 18:16:34 +02:00
parent 3d66bdaea9
commit 3249d249be
1 changed files with 25 additions and 0 deletions

25
classen/FormValidator.php Normal file
View File

@ -0,0 +1,25 @@
<?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])) {
return false;
}
if(isset($params['regex']) && !preg_match($params['regex'], $req[$field])) {
return false;
}
}
return true;
}
}
?>