Add basic input validation class
parent
3d66bdaea9
commit
3249d249be
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue