Your data must be an array, it can be form data, a decoded JSON string or whatever.
Each different validator is a simple standalone class.
But we use a main class to pass through every validators.
Let's see a basic example:
use SimpleValidator\Validator;
use SimpleValidator\Validators;
$data = array('field1' => '1234');
$v = new Validator($data, array(
new Validators\Required('field1', 'field1 is required'),
new Validators\Integer('field1', 'field1 must be an integer'),
));
// Validation error
if (! $v->execute()) {
print_r($v->getErrors()); // Get all validation errors
}
Validators
----------
### Alphanumeric
Allow only letters and digits.
new Validators\AlphaNumeric('column name', 'error message');
### Email
I use the same validation method as Firefox: <http://hg.mozilla.org/mozilla-central/file/cf5da681d577/content/html/content/src/nsHTMLInputElement.cpp#l3967>
So email address like toto+titi@domain.tld are allowed.
new Validators\Email($field, $error_message);
### Integer
Allow only integer, but also strings with digits only.
new Validators\Integer($field, $error_message);
### Length
Allow only strings with a correct length.
new Validators\AlphaLength($field, $error_message, $min, $max);
### Numeric
Allow float, integer and strings with only digits and dot.
new Validators\Numeric($field, $error_message);
### Range
Allow only numbers inside the specified range.
new Validators\Range($field, $error_message, $min, $max);