Server side user input validation library
You can install Validator either via package download from github or via composer install. I encourage you to do the latter:, (*2)
{ "require": { "pingle/validator": "dev-master" } }
This is a small PHP class that makes it easy to validate forms in your project specially larger forms. Pingle Validator class provide the validation for the user input on the server side., (*3)
namespace Pingle/Validator; //initialize the class $val = new Validator(); /*** use POST as the source ***/ $val->addSource($_POST); /*** add a form field rule ***/ /*** addRule('name', 'type', required, min, max, trim, regex)***/ $val->addRule('name', 'string', true, 5, 255, true) ->addRule('email', 'email', true, 1, 255, true) ->addRule('website', 'url', false, 1, 255, true) ->addRule('age', 'numeric', true, 1, 100, true) ->addRule('salary', 'float', false, 1, 99999999, true) ->addRule('date', 'regex', true, 10, 10, true,"#^(((?:0?[1-9]|1[012])|(?:0?[1-9]|[12][0-9]|3[01])|([a-zA-Z]+))([.,]?[-.\\\/\s]))?(((?:0?[1-9]|1[012])|(?:0?[1-9]|[12][0-9]|3[01])|([a-zA-Z]+))([.,]?[-.\\\/\s]))?((?:20|19)[0-9]{2})$#"); /*** run the validation rules ***/ $val->run(); /*** if there are errors show them ***/ if(sizeof($val->errors) > 0) { print_r($val->errors); } else { $_POST=$val->sanitized; }