nikolai/char-validator
最新稳定版本:v1.0
Composer 安装命令:
composer require nikolai/char-validator
包简介
A char validator that validates string by chosen conditions.
README 文档
README
A char validator for Yii2 that validates string by chosen conditions. Inspired by nickcv - https://www.yiiframework.com/user/8296 and his extension for Yii 1.1 - https://www.yiiframework.com/extension/alpha!
Requirements
- Yii2 >= 2.0
- Composer for installation
Installation
composer require nikolai/char-validator
Usage
To use char-validator, install it via Composer, add the new class in the model and then use it in the rules. There are additional parameters that can be used in validation. An example of using with some parameters, also usage of "extra".
use nln\chars\CharValidator; ... public function rules() { return [ [['name'], CharValidator::className(), 'allAccentedLetters' => true, 'allowSpaces'=> true], [['differentname'], CharValidator::className(), 'allAccentedLetters' => true, 'allowSpaces'=> true, 'extra' => array('.', '-', '(', ')', '\'')], ]; }
allowNumbersis a boolean, and defaults to false. Allow the use of numbers into the string.allowSpacesis a boolean and defaults to false. the name is pretty self explanatory.minCharsis an integer and defaults to 1.maxCharsis still an integer and defaults to NULL. If you don't want the validated string to have more then x characters use this parameter.accentedLettersis another boolean. Enables the use of basic accented vowels into the string. See the list below.allAccentedLettersstill a boolean. Enable the use of every accented letter existing in the latin-derived languages. See the list below.extrathis is an array. If you want to allow some other characters (like -) this is the parameter you want to use.messagejust like any other validator you can use this to change the error message. You can use {attribute} in this string as a wild card if you want to.
accentedLetters list
ÀÁÂÃÄĀĂÈÉÊËĚĔĒÌÍÎÏĪĨĬÒÓÔÕÖŌÙÚÛÜŪŬŨàáâãäāăèéêëēěĕ ìíîïīĩĭòóôõöōŏùúûüūŭũ
allAccentedLetters list
ÀÁÂÃÄÅĀĄĂÆÇĆČĈĊĎĐÈÉÊËĒĘĚĔĖĜĞĠĢĤĦÌÍÎÏĪĨĬĮİIJĴĶŁĽĹĻ ĿÑŃŇŅŊÒÓÔÕÖØŌŐŎŒŔŘŖŚŠŞŜȘŤŢŦȚÙÚÛÜŪŮŰŬŨŲŴÝŶŸŹŽŻàá âãäåāąăæçćčĉċďđèéêëēęěĕėƒĝğġģĥħìíîïīĩĭįıijĵķĸłľĺ ļŀñńňņʼnŋòóôõöøōőŏœŕřŗśšşŝșťţŧțùúûüūůűŭũųŵýÿŷžżź ÞþßſÐð
Disclaimer
Keep in mind that this validation rule is not doing any conversion of the string (no htmlspecialchars, no htmlentities). Be always careful about how to save strings containing accented letters into your database.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-17