PHP code example of juanchosl / validators
1. Go to this page and download the library: Download juanchosl/validators 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/ */
juanchosl / validators example snippets
StringValidation::isEmail("[email protected] "); //true
$validator = new StringValidations();
$validator
->is()
->isNotEmpty()
->isLengthGreatherThan(15)
->isEmail();
$validator->getResult('[email protected] '); //true
print_r($validator->getResults('[email protected] '));
Array
(
[is] => 1
[isNotEmpty] => 1
[isLengthGreatherThan: 15] => 1
[isEmail] => 1
)
$validator = new StringValidations();
$validator
->is()
->isNotEmpty()
->isLengthGreatherThan(15)
->isEmail();
foreach(['[email protected] ', '[email protected] '] as $text){
$validator->getResult($text); //true
print_r($validator->getResults($text));
Array
(
[is] => 1
[isNotEmpty] => 1
[isLengthGreatherThan: 15] => 1
[isEmail] => 1
)
}
$validator = new StringValidations();
$validator
->is()
->isNotEmpty()
->isValueEqualsAny('juan','pepe','antonio')
->getResult('juan'); //true
$datas = [
["nombre" => "pepe", "apellidos" => "salmuera", "email" => "[email protected] ", "telephone" => 123456789],
["nombre" => "juan", "apellidos" => "benito", "email" => "[email protected] ", "telephone" => 123456789],
];
$validator = new EntityValidations();
$validator->isValueAttributeValidating('email', (new StringValidations())->isEmail());
$validator->isValueAttributeValidating('telephone', (new IntegerValidations())->isLengthGreatherOrEqualsThan(9)->isLengthLessOrEqualsThan(12));
foreach($datas as $data){
$validator->getResult($data);
}
$validator = new IterableValidations();
$validator
->is()
->isNotEmpty()
->isKeyContainingAny(...['nombre', 'apellidos']);
->getResult(['nombre' => 'Cadena numeros', 'apellidos' => 'Cadena letras']);//true
***********
$datas = [
["nombre" => "pepe", "apellidos" => "salmuera", "email" => "[email protected] ", "telephone" => 123456789],
["nombre" => "juan", "apellidos" => "benito", "email" => "[email protected] ", "telephone" => 123456789],
];
$validator->isValueAttributeValidating('email', (new StringValidations())->isEmail());
$validator->isValueAttributeValidating('telephone', (new IntegerValidations())->isLengthGreatherOrEqualsThan(9)->isLengthLessOrEqualsThan(12));
$validator->getResult($datas);
************
$datas = ["[email protected] ", "[email protected] "];
$validator = new IterableValidations();
$validator->isValueValidating((new StringValidations())->isEmail());
$validator->getResult($datas);