Git Product home page Git Product logo

validator's Introduction

image

Travis-CI Packagist Packagist downloads Scrutinizer Scrutinizer

Particle\Validator is a very small validation library, with the easiest and most usable API we could possibly create.

Install

To easily include Particle\Validator into your project, install it via composer using the command line:

composer require particle/validator

Small usage example

use Particle\Validator\Validator;

$v = new Validator;

$v->required('user.first_name')->lengthBetween(2, 50)->alpha();
$v->required('user.last_name')->lengthBetween(2, 50)->alpha();
$v->required('newsletter')->bool();

$result = $v->validate([
    'user' => [
        'first_name' => 'John',
        'last_name' => 'D',
    ],
    'newsletter' => true,
]);

$result->isValid(); // bool(false).
$result->getMessages();
/**
 * array(1) {
 *     ["user.last_name"]=> array(1) {
 *         ["Length::TOO_SHORT"]=> string(53) "last_name is too short and must be 2 characters long."
 *     }
 * }
 */

Functional features

  • Validate an array of data
  • Get an array of error messages
  • Overwrite the default error messages on rules, or error messages on specific values
  • Get the validated values of an array
  • Validate different contexts (insert, update, etc.) inheriting validations of the default context
  • A large set of default validation rules
  • Ability to extend the validator to add your own custom rules

Non functional features

  • Easy to write (IDE auto-completion for easy development)
  • Easy to read (improves peer review)
  • Ability to separate controller and view logic
  • Fully documented: validator.particle-php.com
  • Fully tested: Scrutinizer
  • Zero dependencies

===

Find more information and advanced usage examples at validator.particle-php.com

validator's People

Contributors

adriansuter avatar berry-langerak avatar camcima avatar creocoder avatar jaapverloop avatar jaytaph avatar lguima avatar localheinz avatar nickbelhomme avatar noahlemen avatar rcatlin avatar rtuin avatar schnittstabil avatar skoop avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.