Skip to content

Validators implementing Validator interface / abstract

License

Notifications You must be signed in to change notification settings

district-5/php-validators

Repository files navigation

codecov

Validators

A collection of validators implementing / extending the District5 Validator library.

Installation

Install using composer:

composer require district5/validators

Usage

Currently Available Validators

  • Array of Numbers
  • Bool Value
  • Checkbox Value
  • DateTime
  • DateYYYMMDD
  • Domain Name
  • Email Address
  • Hex
  • Hex Colour
  • Integer Value
  • Integer Positive
  • Integer Range
  • JSON String
  • Lat Lon Object
  • Long Value
  • Numeric Value
  • Numeric Range
  • Numeric Specific Values
  • Regex
  • Std Class with Properties
  • String in Array of String
  • String Length
  • String of Defined Characters
  • String Version Major Minor Patch Greater Than or Equal To
  • String with Dashes
  • String with Dashes and Underscores
  • String with Dashes Dots and Underscores
  • Sub Domain
  • Unix Timestamp Seconds
  • URL

General

Most validators work in the same way:

$validValue = true;
$invalidValue = 'Hello';

$validator = new \District5\Validators\BoolValue();

$validator->isValid($validValue);   // true
$validator->isValid($invalidValue);   // false

Some validators have configuration options that can be specified at construction time:

EmailAddress

Validate an email address:

<?php
// Simple format check:
$validator = new \District5\Validators\EmailAddress();
$validator->isValid('[email protected]'); // true

// Deeper check, which includes MX record lookup:
$validator = new \District5\Validators\EmailAddress(
    ['deep' => true]
);

$validator->isValid('[email protected]'); // true
$validator->isValid('[email protected]'); // false

Testing:

$ composer install
$ ./vendor/bin/phpunit

About

Validators implementing Validator interface / abstract

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages