1. Go to this page and download the library: Download popphp/pop-validator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
popphp / pop-validator example snippets
$validator = new Pop\Validator\Email();
// Returns false
if ($validator->evaluate('bad-email-address')) {
// Prints out the default message 'The value must be a valid email format.'
echo $validator->getMessage();
}
// Returns true
if ($validator->evaluate('[email protected]')) {
// Do something with a valid email address.
}
$validator = new Pop\Validator\LessThan(10);
if ($validator->evaluate(8)) { } // Returns true
$validator = new Pop\Validator\RegEx(
'/^.*\.(jpg|jpeg|png|gif)$/i',
'You must only submit JPG, PNG or GIF images.'
);
// Returns false
if ($validator->evaluate('image.bad')) {
echo $validator->getMessage();
}
$validator = new Pop\Validator\RegEx('/^.*\.(jpg|jpeg|png|gif)$/i');
$validator->setMessage('You must only submit JPG, PNG or GIF images.');
if ($validator->evaluate('image.jpg')) { } // Returns true
use Pop\Validator\ValidatorSet;
$set = new ValidatorSet();
$set->addValidators(['username' => 'AlphaNumeric']);
if ($set->evaluate(['username' => 'username_123'])) {
echo 'The username satisfies the
use Pop\Validator\ValidatorSet;
$set = new ValidatorSet();
$set->addValidators(['username' => ['AlphaNumeric' => null, 'LengthGte' => 8]]);
if ($set->evaluate(['username' => 'username_123'])) {
echo 'The username satisfies the
use Pop\Validator\ValidatorSet;
$set = new ValidatorSet();
$set->addValidators([
'username' => [
'AlphaNumeric' => [
'value' => null,
'message' => 'The username can only contain alphanumeric characters.'
],
'LengthGte' => 8
]
]);
if ($set->evaluate(['username' => 'username_123'])) {
echo 'The username satisfies the
use Pop\Validator\ValidatorSet;
$set = ValidatorSet();
$set->addValidators(['username' => ['AlphaNumeric' => null, 'LengthGte' => 8]]);
$set->setStrict(ValidatorSet::STRICT_NONE);
if ($set->evaluate(['username' => 'someuser_!23'])) {
echo 'The username satisfies the
use Pop\Validator\ValidatorSet;
use Pop\Validator\Condition;
$set = new ValidatorSet();
$set->addCondition(new Condition('client_id', 'Equal', '1'));
$set->addValidator('documents', 'NotEmpty');
$data = [
'client_id' => 1,
'documents' => [
'some_file_1.pdf',
'some_file_2.pdf',
]
];
if ($set->evaluate($data)) {
echo 'The client order data satisfies the
$set = Pop\Validator\ValidatorSet::createFromRules([
'username:alpha_numeric',
'username:length_gte:8'
]);
if ($set->evaluate(['username' => 'someuser_123'])) {
echo 'The username satisfies the
use Pop\Validator\ValidatorSet;
$set = ValidatorSet::createFromRules('documents:not_empty')
->addConditionFromRule('client_id:equal:1');
$data = [
'client_id' => 1,
'documents' => [
'some_file_1.pdf',
'some_file_2.pdf',
]
];
if ($set->evaluate($data)) {
echo 'The client order data satisfies the
$set = Pop\Validator\ValidatorSet::createFromRules([
'username:length_gt:8:The username must be greater than 8 characters.'
]);
use Pop\Validator\ValidatorSet;
$set = ValidatorSet::createFromRules('value_1:equal:[value_2]');
$data = [
'value_1' => 'test',
'value_2' => 'test'
];
if ($set->evaluate($data)) {
echo 'The data satisfies the
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.