The most complete rule _yii framework for YII rules

Source: Internet
Author: User
Tags dateformat valid email address mx record yii
This article uses Yii documentation, which is modified to make it easier for readers to understand the alias of a predefined complete list:  boolean : cbooleanvalidator . Make sure the value of the property is cbooleanvalidator::truevalue  or cbooleanvalidator::falsevalue . The alias of the captcha : ccaptchavalidator  ensures that the value of the attribute is equal to the verification code displayed by  CAPTCHA . compare : ccomparevalidator  alias to ensure that the value of the attribute equals another attribute or constant. email : cemailvalidator  alias to ensure that the value of the attribute is a valid email address. A default : cdefaultvaluevalidator  alias that assigns a default value to the attribute. exist : cexistvalidator  alias to ensure that the property value exists in the specified data table field. file : cfilevalidator  alias to ensure that the attribute contains the name of an uploaded file. filter : cfiltervalidator  alias, using a filter transformation attribute. The alias for the in : crangevalidator  ensures that the attribute appears in the list of values in a subscription. The alias of the length : cstringvalidator  ensures that the length of the attribute is within the specified range. The alias of the match : cregularexpressionvalidator  ensures that the attribute matches a regular expression. The alias of the numerical : cnumbervalidator  ensures that the attribute is a valid number. required : crequiredvalidator  alias to ensure that the attribute is not empty. type : ctypevalidator  alias to ensure that theattribute is the specified data type. The alias for the unique : cuniquevalidator  ensures that the attribute is unique in the Data table field. url : curlvalidator  alias to ensure that the feature is a valid path  
Note: The first and second values in the following array are required, and the value of the message is Error ==================================================== 1. Reqiurd (crequiredvalidator)-----must validate the attribute: instance: Array (' name ', ' Required ', ' requiredvalue ' => ', ' "strict ' => true, ' Message ' => ' please fill in the name '): requiredvalue------Mixed the required value strict-------boolean------is more stringent ======================= =============================
2. Filter (Cfiltervalidator)-----Filtering Verification Method: instance: Array (' name ', ' Test ', ' message ' => ' please fill in name ') Public function test ($obje CT, $attributes) {if ($this->name!= ' Zhang Xianxin ') {$this->adderror ($object, $attribut           es [' message ']); Explain:
Filte----Method Name (calls the user-defined function) ====================================================
3. Match (Cregularexpressionvalidator)-----Regular Validation Properties: instance: Array (' name ', ' Match ', ' AllowEmpty ' => ' true ', ' not ' => ') True ', ' pattern ' => '/[a-z]/i ', ' message ' => ' must not be a parent ') explained:
AllowEmpty------Boolean-----can be null (default is True) not-------boolean------reverse validation logical pattern-------Boolean------Regular method ===== ===============================================
4. Email (cemailvalidator)-----Mailbox Verification Attribute: instance: Array (' name ', ' email ', ' allowempty ' => ' true ', ' pattern ' => '/[a-z]/i ', ' Message ' => ' must not be a parent ') explained:
AllowEmpty------Boolean-----can be null (default is True) pattern-------Boolean------Regular method Allowname-------Boolean------whether to allow checkmx of the name of the e-mail address-------boolean------whether to check the MX record of the e-mail address ========================= ===========================
5. URL (curlvalidator)-----URL validation attribute: instance: Array (' name ', ' url ', ' AllowEmpty ' => ' true ', ' pattern ' => '/[a-z]/i ', ' Message ' => ' must not be a parent ') explained:
AllowEmpty------Boolean-----can be null (default is True) pattern-------Boolean------Regular method Defaultscheme-------boolean------The default URL scheme validschemes-------A boolean------list should be considered a valid URL plan ======================== ============================
6. Unique (cuniquevalidator)-----Uniqueness Validation Attribute: instance: Array (' name ', ' unique ', ' AllowEmpty ' => ' true ', ' casesensitive ' => ') True ', ' message ' => ' must not be a parent ') to explain:
AllowEmpty whether the-----------can be empty (the default is True) casesensitive-------------case-sensitive =========================================== =========
7. Compare (Ccomparevalidator)-----Comparison Validation Properties: instance: With a value ratio: Array (' name ', ' compare ', ' AllowEmpty ' => ' true ', ' CompareValue ') => ', ' operator ' => ' > ', ' message ' => ' must be greater than 10 ') compared to a committed property: Array (' name ', ' compare ', ' AllowEmpty ' => ' true ', ' compareattribute ' => ' password ', ' operator ' => ' > ', ' message ' => ' must be greater than password ')
Explain:
AllowEmpty-----------Whether it can be null (the default is True) Compareattribute-------------the property that needs to be compared CompareValue-------------the value that needs to be compared Operator-------------comparison operator strict-------------strict execution (both values and types are equal) =================================================== =
8. Length (cstringvalidator)-----String Validation attribute: instance: is within a range: Array (' name ', ' length ', ' AllowEmpty ' => ' true ', ' Max ' => ' 10 ', ' min ' => ' 5 ', ' Toolong ' => ' too long ', ' tooshort ' => ' too short ') must be of a certain length: array (' name ', ' length ', ' is ', ' # ', ' is ' => ' 5 ', ' message ') => ' length must be 5 ')
Explain:
AllowEmpty-----------can be null (default is TRUE) encoding-------------encoding is-------------exact length max-------------max length Min-------------Minimum length toolong-------------the error tooshort the definition value is too large-------------the error that defines the value is too large ================================= ===================
9. In (crangevalidator)-----A range of properties: instance: must be within a range: Array (' name ', ' in ', ' Range ' => array (1,2,3,4,5), ' message ' => ' value Must be 1,2,3,4,5 ') cannot be within a range: Array (' name ', ' in ', ' isn't ' => ' true ', ' range ' => array (1,2,3,4,5), ' message ' => ' value cannot be 1, 2,3,4,5 ')
Explain:
AllowEmpty-----------Whether it can be null (the default is true) not-------------whether to reverse the validation logic range-------------Array range Strict-------------strictly enforced (both values and types are equal) ====================================================
Numerical (cnumbervalidator)-----Digital Validation attribute: instance: Must be an integer: Array (' name ', ' numerical ', ' integeronly ' => ' true ', ' message ') => ' value must be an integer ' value must be within a range: Array (' name ', ' numerical ', ' integeronly ' => ' true ', ' message ' => ' value must be an integer ', ' Max ' => ' 1 ', ' min ' => ', ' toobig ' => ' value is too big ', ' toosmall ' => ' value is too small ')
Explain:
AllowEmpty-----------Whether it can be null (the default is True) integeronly-------------integer integerpattern-------------Regular expression matches an integer Max-------------Max min-------------minimum numberpattern-------------matching number toobig-------------value is too large Toosmall tips for-------------value too small ====================================================
CAPTCHA (ccaptchavalidator)-----Verification Code Validation attribute: instance: Array (' name ', ' Captcha ', ' casesensitive ' => ' true ', ' message ' =& Gt "Incorrect verification Code") explains:
AllowEmpty whether the-----------can be empty (the default is True) casesensitive-------------case-sensitive =========================================== =========
Type Ctypevalidator-----Types Validation Properties: instance: Array (' name ', ' type ', ' DateFormat ' => ' mm/dd/yyyy ', ' type ' => ' date ') , ' message ' => ' type is not correct ') explained:
AllowEmpty-----------Whether it can be empty (the default is True) DateFormat the format pattern (' mm/dd/yyyy ') to be followed for the date------------- DateTimeFormat format pattern to be followed-------------datetime (' mm/dd/yyyy hh:mm ')
TimeFormat-------------The format pattern (' hh:mm ') type-------------type ' string ', ' integer ', ' float ', ' array ', ' Date ', ' time ', ' DateTime ' ====================================================
Cfilevalidator-----File Validation Properties: instance: Array (' name ', ' file ', ' Types ' => array (' jpg ', ' gif ', ' png '), ' message ' =& Gt "Incorrect file format") explains:
AllowEmpty-----------can be null (the default is True) Maxfiles-----------maximum number of files maxSize-----------file maximum minsize-----------file minimum Toolarge-----------File too large error message Toomany-----------file too many error messages Toosmall-----------file is too small error message types-----------allowed extensions Wrongtype error message when-----------extension error ====================================================
Cdefaultvaluevalidator-----Default Value property: instance: Array (' name ', ' Default ', ' Setonempty ' => ' true ', ' value ' => ' 123 ') explained:
Setonempty-----------set to null value-----------default ====================================================
exist (Cexistvalidator)-----Existence of attributes: Explanation:
AllowEmpty-----------can be null (the default is True) AttributeName-----------property name ClassName-----------class name criteria-----------= = =================================================
Cbooleanvalidator-----Boolean Type Validation properties: instance: Array (' Name ', ' Boolean ', ' TrueValue ' => ' 1 ', ' falsevalue ' => '-1 ') , ' message ' => ' This value can only be 1 or-1 ')
Explain:
AllowEmpty-----------Whether it can be null (the default is True) Falsevalue the value of the-----------Error state strict-----------strictly verify the value of the TrueValue-----------true state

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.