pingle/validator
Composer 安装命令:
composer require pingle/validator
包简介
Server side user input validation library
README 文档
README
You can install Validator either via package download from github or via composer install. I encourage you to do the latter:
{
"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.
Basic usage
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; }
Validation Methods
- string
- url
- numeric
- float
- regex
- ipv4
- ipv6
- bool
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-06-06