1. Go to this page and download the library: Download bootpress/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/ */
bootpress / validator example snippets
use BootPress\Validator\Component as Validator;
$validator = new Validator($_POST);
// Require a name value
$validator->set('name', 'e one as well
$validator->set('email', 'Numeric|minLength[5]|noWhiteSpace', // Using a pipe separated string
'confirm' => array('r all fields
$validator->errors['
if ($vars = $validator->certified()) {
// Process $vars
} else {
// The form was either not submitted, or there were errors
}
Validator::number(1.345); // true - this is a number
Validator::number('string'); // false
Validator::integer(1000); // true
Validator::integer(1.345); // false - must be a whole number
Validator::digits(1000); // true
Validator::digits(1.345); // false - no periods allowed
Validator::min(5, 3); // true - 5 is greater than 3
Validator::min(3, 5); // false - 3 is less than 5
Validator::max(5, 3); // false - 5 is greater than 3
Validator::max(3, 5); // true - 3 is less than 5
Validator::range(5, array(2, 7)); // true
Validator::range(5, array(6, 7)); // false
Validator::alphaNumeric('abc123'); // true
Validator::alphaNumeric('abc-xyz'); // false
Validator::minLength('string', 2); // true
Validator::minLength('string', 7); // false
Validator::maxLength('string', 7); // true
Validator::maxLength('string', 2); // false
Validator::rangeLength('string', array(2, 6)); // true
Validator::rangeLength('string', array(7, 15)); // false
Validator::rangeLength(array(1, 2), array(2, 4)); // true - there are between 2 and 4 elements in array(1, 2)
Validator::rangeLength(array(1, 2), array(3, 5)); // false - 2 elements is outside the range of 3 and 5
Validator::minWords('one two three', 1); // true
Validator::minWords('one two three', 5); // false
Validator::maxWords('one two three', 5); // true
Validator::maxWords('one two three', 1); // false
Validator::rangeWords('one two three', array(1, 3)); // true
Validator::rangeWords('one two three', array(0, 2)); // false
// Allows phone numbers with optional country code, optional special characters and whitespace
$phone_number = '/^([+]?\d{1,2}[-\s]?|)\d{3}[-\s]?\d{3}[-\s]?\d{4}$/';
Validator::pattern('907-555-0145', $phone_number); // true
Validator::pattern('555-0145', $phone_number); // false
Validator::date('2015-12-31'); // true
Validator::date('infinite'); // false
Validator::email('[email protected]'); // true
Validator::email('[email protected]'); // false
Validator::url('http://example.com'); // true
Validator::url('example.com'); // false
Validator::ipv4('175.16.254.1'); // true
Validator::ipv4('2001:0db8:0000:0000:0000:ff00:0042:8329'); // false
Validator::ipv6('2001:0db8:0000:0000:0000:ff00:0042:8329'); // true
Validator::ipv6('175.16.254.1'); // false
Validator::inList('2', array(1, 2, 3)); // true
Validator::inList(7, array(1, 2, 3)); // false
Validator::noWhiteSpace('whitespace'); // true
Validator::noWhitespace('white space'); // false
Validator::singleSpace('single space'); // 'single space'
Validator::singleSpace('single space'); // 'single space'
Validator::trueFalse(101)); // 1
Validator::trueFalse('true')); // 1
Validator::trueFalse('n')); // 0
Validator::trueFalse(0)); // 0
Validator::yesNo(101)); // 'Y'
Validator::yesNo('true')); // 'Y'
Validator::yesNo('n')); // 'N'
Validator::yesNo(0)); // 'N'
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.