quantumunit/php-validation
Composer 安装命令:
composer require quantumunit/php-validation
包简介
php validation library
关键字:
README 文档
README
my first crack at learning PHP back in 2007. Rewritten in 2014 to use YAML instead of XML. Changed from Chain of Command pattern to use basic Load-On-Demand instead.
Usage:
$loader = new YamlConfiguration();
$loader->loadConfig(__SITE_PATH . '/validation-config.yml');
//YAML key $key = 'new_user_signup'; $validator = new Validator($loader, $this->getLogger()); //Monolog\Logger
$result = $validator->validateRequest($key, $this->getPostedParams());
Notes:
if $result is an array holding values, it will be an associative array where the fieldname is the index key and the LANG_STRING (for multi-locale support) is the value of that index.
sample YAML config (validation-config.yml):
failkey: some_other_yml_key
fields:
#uses 2 validation routines in this example, Required then String
- firstname:
-
class: Required
failkey: VALIDATION_REQUIRED_FIELD
-
class: String
failkey: VALIDATION_INVALID_STRING
params:
maxlength: 20
- lastname:
-
class: Required
failkey: VALIDATION_REQUIRED_FIELD
-
class: String
failkey: VALIDATION_INVALID_STRING
params:
maxlength: 20
#email is optional in this sample so no Required validation needed - email - class: Email failkey: VALIDATION_INVALID_EMAIL
Possible Validation Classes:
Address
AlphaNumeric - letters and numbers only
Alphabet - letters only
BusinessName - letters, numbers, apostrophe, and &()-,.
Currency
Date
Email
IPAddress
Integer
Required
String - letters, spaces and apostrophes
Telephone
URL
统计信息
- 总下载量: 217
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-05-25