2017 © Pedro Peláez
 

library request-validator

Simple PHP Request Validator

image

progsmile/request-validator

Simple PHP Request Validator

  • Tuesday, July 12, 2016
  • by daison12006013
  • Repository
  • 5 Watchers
  • 25 Stars
  • 23,987 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 3 Versions
  • 54 % Grown

The README.md

PHP Request Validator

Make your apps validation easily (inspired by Laravel Validation), (*1)

Build Status Total Downloads License, (*2)


Page Index: - Quick Start - Contributing - Testing - License, (*3)

Suggested Links: - Installation - Feature Guide - Rules - Existing Rules - Adding custom Rules - Formatting Message, (*4)


, (*5)

Quick start :rocket:

<?php

$rules = [
    # firstname and lastname must be present
    # they should be alphanumeric
    # atleast 2 characters
    'firstname, lastname' => 'required|alpha|min:2',

    # max until 18 characters only
    'lastname'            => 'max:18',

    # must be an email format
    # adding custom rule
    'email'               => ['email', MyCustomRule::class],

    # must be numeric
    'id'                  => 'numeric',
    'age'                 => ['min:16', 'numeric'],
    'info[country]'       => ['required', 'alpha'],

    # roll[0] or roll[1] values must be in the middle 1 to 100
    'roll[0], roll[1]'    => 'numeric|between:1, 100',

    # the format must be 'm-Y.d H:i'
    'date'                => 'dateFormat:(m-Y.d H:i)',

    # it must be an image format under $_FILES global variable
    'profileImg'          => 'image',

    # the provided phone number should follow the format
    # correct: +38(123)456-12-34
    # wrong: +38(123)56-123-56
    # wrong: +39(123)456-12-34
    'phoneMask'           => 'phoneMask:(+38(###)###-##-##)',
    'randNum'             => 'between:1, 10|numeric',

    # the value must be an IP Format
    'ip'                  => 'ip',
    'password'            => 'required|min:6',

    # the value from a key 'password' must be equal to 'password_repeat' value
    'password_repeat'     => 'same:password',

    # it must be a json format
    'json'                => 'json',
    'site'                => 'url',

    # cash10 or cash25 must only have these
    # 1 or 2 or 5 or 10 or 20 or 50
    'cash10, cash25'      => 'in:1, 2, 5, 10, 20, 50',

    # the value must not have 13 or 18 or 3 or 4
    'elevatorFloor'       => 'notIn:13, 18, 3, 4',
];

$customMessage = [
   'info[country].alpha' => 'Only letters please',
   'email.required'      => 'Field :field: is required',
   'email.email'         => 'Email has bad format',
   'email.unique'        => 'This email :value: is not unique',
   'elevatorFloor.notIn' => 'Oops',
];

$validation = \Progsmile\Validator\Validator::make($_POST, $rules, $customMessage);

# for specific field
# you can use below code.
$validation->lastname->passes();
$validation->lastname->fails();

# if you're required to check everything
# and there must no failing validation
$validation->passes();
$validation->fails();

# get first error message
$validation->first();

# get first error for `firstname`
$validation->first('lastname');
$validation->firstname->first();

# return first error message from each field
$validation->firsts();

# get all messages (with param for concrete field)
$validation->messages();
$validation->messages('password');

# get all `password` messages
$validation->password->messages();

# get 2d array with fields and messages
$validation->raw();

# to append a message
$validation->add('someField', 'Something is wrong with this');

, (*6)

Contributing :octocat:

Dear contributors , the project is just started and it is not stable yet, we love to have your fork requests., (*7)

, (*8)

Testing

This testing suite uses Travis CI for each run. Every commit pushed to this repository will queue a build into the continuous integration service and will run all tests to ensure that everything is going well and the project is stable., (*9)

The testing suite can be run on your own machine. The main dependency is PHPUnit which can be installed using Composer:, (*10)

# run this command from project root
$ composer install --dev --prefer-source
$ vendor/bin/phpunit --configuration phpunit.xml --coverage-text

For additional information see PHPUnit The Command-Line Test Runner., (*11)

, (*12)

License

PHP Request Validator is open-sourced software licensed under the GNU GPL. © 2020 Denys Klymenko and all the contributors., (*13)

The Versions

12/07 2016

dev-master

9999999-dev

Simple PHP Request Validator

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

by Denis K

php form validation security sanitization modeling

12/03 2016

1.1.1

1.1.1.0

Simple PHP Request Validator

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

by Denis K

php form validation security sanitization modeling

26/02 2016

dev-analysis-8PxM69

dev-analysis-8PxM69

Simple PHP Request Validator

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4

 

The Development Requires

by Denis K

php form validation security sanitization modeling