Pop Validator Component
Switch branches/tags
Nothing to show
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Update license & copyright Jan 29, 2018
tests Patch contains/notcontains classes Feb 17, 2017
.gitattributes Update version, add gitattributes Jul 10, 2015
.gitignore Write the unit tests Jun 22, 2015
.travis.yml First commit v3 Oct 16, 2016
LICENSE.TXT Update license & copyright Jan 29, 2018
README.md Update README Feb 22, 2017
composer.json Update license Jan 29, 2018
phpunit.xml Write the unit tests Jun 22, 2015



Build Status Coverage Status


pop-validator is a component for validating values and returning the appropriate result messaging. The component comes with a set of built-in evaluation objects and also the ability to extend the component and build your own.

pop-validator is a component of the Pop PHP Framework.


Install pop-validator using Composer.

composer require popphp/pop-validator


Here's a list of the available built-in validators:

Built-in Validators
AlphaNumeric Ipv4 LessThanEqual
Alpha Ipv6 LessThan
BetweenInclude IsSubnetOf NotContains
Between LengthBetweenInclude NotEmpty
Contains LengthBetween NotEqual
CreditCard LengthGte Numeric
Email LengthGt RegEx
Equal LengthLte Subnet
GreaterThanEqual LengthLt Url
GreaterThan Length

Check an email value

$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('good@email.com')) {
    // Do something with a valid email address.

Validate against a specific value

$validator = new Pop\Validator\LessThan(10);

if ($validator->evaluate(8)) { } // Returns true

Set a custom message

$validator = new Pop\Validator\RegEx(
    '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