webtoolsnz/yii2-validators
最新稳定版本:0.1.8
Composer 安装命令:
composer require webtoolsnz/yii2-validators
包简介
A collection of yii2 validators.
关键字:
README 文档
README
A collection of Yii2 validators for various localities.
Installation
The preferred way to install this extension is through composer.
$ composer require webtoolsnz/yii2-validators
Example Use
Model Validation rules
use webtoolsnz\validators\en_AU\NmiValidator;
class MyModel extends \yii\base\Model
{
public function rules()
{
return [
[['nmi'], NmiValidator::className()]
];
}
}
Adhoc Validation
$validator = new webtoolsnz\validators\en_AU\NmiValidator();
$validator->validate('NGGG0000554');
Available Validators
- PasswordStrengthValidator
- PhoneNumberValidator
en_AU
- NmiValidator
- AbnValidator
- PhoneNumberValidator
en_GB
- PostCodeValidator
- PhoneNumberValidator
Phone Number Validation
Use webtoolsnz\validators\en_GB\PhoneNumberValidator or webtoolsnz\validators\en_AU\PhoneNumberValidator for simpilicity (no options required) for other regions use webtoolsnz\validators\PhoneNumberValidator
Options defined as follows
$rules = [ [ 'phone', webtoolsnz\validators\PhoneNumberValidator::className(), // ISO 2 letter country code - Required (unless using en_GB or en_AU versions) will convert // 021 => +6421 'expectedRegion' => 'NZ', // auto fills expectedRegion - phone number MUST be from this region 'requiredRegion' => 'NZ', // number is required to match type, NUMBER_TYPE_FIXED_LINE is also available 'numberType' => PhoneNumberValidator::NUMBER_TYPE_MOBILE, // will re-format input to match the given format. Values are FORMAT_NATIONAL FORMAT_E164 and FORMAT_INTERNATIONAL 'format' => PhoneNumberValidator::FORMAT_E164, // some error messages are also customizable ];
Testing
webtoolsnz/yii2-validators has a PHPUnit test suite. To run the tests, run the following command from the project folder.
$ composer test
License
The MIT License (MIT). Please see LICENSE for more information.
统计信息
- 总下载量: 63.2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2016-03-17