定制 nikolai/char-validator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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!

License

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('.', '-', '(', ')', '\'')],
        ];
    }
  • allowNumbers is a boolean, and defaults to false. Allow the use of numbers into the string.
  • allowSpaces is a boolean and defaults to false. the name is pretty self explanatory.
  • minChars is an integer and defaults to 1.
  • maxChars is still an integer and defaults to NULL. If you don't want the validated string to have more then x characters use this parameter.
  • accentedLetters is another boolean. Enables the use of basic accented vowels into the string. See the list below.
  • allAccentedLetters still a boolean. Enable the use of every accented letter existing in the latin-derived languages. See the list below.
  • extra this is an array. If you want to allow some other characters (like -) this is the parameter you want to use.
  • message just 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
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-17