PHP Classes

User Input Validator: Validate request values according to given rules

Recommend this page to a friend!
  Info   View files Documentation   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 284 This week: 1All time: 7,559 This week: 560Up
Version License PHP version Categories
input-validator 1.2MIT/X Consortium ...5.4HTTP, PHP 5, Validation
Description 

Author

This class can validate request values according to given rules.

It can take a array with the definitions of rules to validate values passed via POST or GET.

The class can check either the $_GET or $_POST array to verify if the values satisfy the defined rules.

It performs the supported types of validations using regular expressions. Currently it supports the validations of alphabetic strings with spaces, numbers or symbols, just numbers, just symbols, number or symbols, phone numbers, boolean or binary values.

Picture of Gavin Gordon Markowski
  Performance   Level  
Name: Gavin Gordon Markowski <contact>
Classes: 13 packages by
Country: Canada Canada
Age: 36
All time rank: 178641 in Canada Canada
Week rank: 416 Up11 in Canada Canada Up
Innovation award
Innovation award
Nominee: 5x

Documentation

InputValidator v1.0.0

Build Status

Prologue

Quickly define and run validation check on user data provided upon either GET or POST requests.

Installation (via Composer)

composer require gavinggordon/input-validator

Include autoloader.php

include_once( __DIR__ . '/vendor/autoload.php' );

Examples

Set Rules

The rules array contains the validation rules for each input. Each input is equal to 1 array, and, in itself, contains the rules for its own validation.

The first parameter of an input's validation array is used to define the Regex pattern by which to validate its value against.

The second parameter, which is also an array, is used to define the string length of the value, noted by the first parameter as a minimum length, followed by a maximum length.

$rules = [
  [
    'alpha', [ 5,16 ]
  ],
  [
    'phone', [ 7,15 ]
  ],
  [
    'alpha_number_symbol_spaces', [ 2,155 ]
  ]
];

Create Instance

To instantiate the class, two arguments are required:

The first argument must be a string value of either 'GET' or 'POST', and is used to determine the request type being validated.

The second argument must be an array of rules, as mentioned in the above example.

$validator = new GGG\InputValidator( 'POST', $rules );

Run the Validator

$validated = $validator->validate();

Determine if Validated

// if passed validation 
if( $validated === true ) {

  // retrieve an associative array of inputs
  $data = $validator->getInputs();
  
}

// if has errors 
if( is_array( $validated ) ) {

  // show an array containing messages for
  // each input which did not pass validation.
  var_dump( $validated );
  
}

More Information

Feedback

If you found this class to be at all interesting, helpful, particularly useful, or innovative in any way, check out my other PHP classes via my GitHub profile or PHPClasses.org profile.


  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Composer.json
Accessible without login Plain text file LICENSE.txt Doc. Documentation
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. README

  Files folder image Files  /  src  
File Role Description
  Plain text file InputValidator.php Class Main class file

 Version Control Unique User Downloads Download Rankings  
 100%
Total:284
This week:1
All time:7,559
This week:560Up