2017 © Pedro Peláez
 

library validation

PHP validation library

image

svil4ok/validation

PHP validation library

  • Wednesday, March 22, 2017
  • by svil4ok
  • Repository
  • 0 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 8 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

PHP Validation Library

Build Status, (*1)

Simple and lightweight standalone PHP library for validating data., (*2)

Usage

<?php

use SGP\Validation\Validator;

$input = [
    'name' => 'Svilen Popov',
    'comment' => 'This a comment',
    'users' => [
        [
            'age' => 20,
            'username' => 'username1'
        ],
        [
            'age' => 16,
            'username' => 'username2'
        ]
    ]
];

$rules = [
    'name' => 'required',
    'comment' => 'required|min:20',
    'users.*.age' => 'required|min:18'
];

$messages = [
    'comment.min' => 'Your comment should have at least 20 chars.'
];

$validator = Validator::make($input, $rules, $messages);

$errors = $validator->errors()->all();

foreach ($errors as $error) {
    echo $error . PHP_EOL;
}

and the above example will output:, (*3)

Your comment should have at least 20 chars.
The users.1.age minimum is 18

Available rules

Alpha Integer
Alpha-Numeric Max
Boolean Min
Date after Numeric
Date before Required
Date

- alpha

Checks if the value contains only alphabetic characters., (*4)

'field' => 'alpha'
- alpha_num

Checks if the valuecontains only alpha-numeric characters., (*5)

'field' => 'alpha_num'
- boolean

Checks if the value is able to be cast as a boolean. Accepted input are true, false, 1, 0, "1", and "0"., (*6)

'field' => 'boolean'
- date_after:param

Checks if the value is a valid date and is after a given date., (*7)

'field' => 'date_after:2017-01-01'
- date_before:param

Checks if the value is a valid date and is before a given date., (*8)

'field' => 'date_before:2017-01-01'
- date

Checks if the value is a date/time string in the input format., (*9)

'field' => 'date'
- max:int

Checks if the value is an integer., (*10)

'field' => 'int'
- max:param

Checks if the value is less than given size. The rule works for strings, numerics and arrays., (*11)

'field' => 'max:20'
- min:param

Checks if the value is greater than given size. The rule works for strings, numerics and arrays., (*12)

'field' => 'max:20'
- max:numeric

Checks if the value is numeric., (*13)

'field' => 'numeric'
- required

Checks if the value is not empty or null., (*14)

'field' => 'required'

The Versions

22/03 2017

dev-master

9999999-dev

PHP validation library

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Svilen Popov

21/03 2017

dev-develop

dev-develop

PHP validation library

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Svilen Popov