More commonly used rules validation rule records in Yii

Source: Internet
Author: User

View Code

Print
01 returnarray(
02
03     //必须填写
04     array(‘email, username, password,agree,verifyPassword,verifyCode‘‘required‘),
05
06     //检查用户名是否重复
07     array(‘email‘,‘unique‘,‘message‘=>‘用户名已占用‘),
08
09     //用户输入最大的字符限制
10     array(‘email, username‘‘length‘‘max‘=>64),
11     
12     //限制用户最小长度和最大长度
13     array(‘username‘‘length‘‘max‘=>7, ‘min‘=>2, ‘tooLong‘=>‘用户名请输入长度为4-14个字符‘‘tooShort‘=>‘用户名请输入长度为2-7个字‘),
14
all    ;    //limit password minimum and maximum length
16     array(‘password‘‘length‘‘max‘=>22, ‘min‘=>6, ‘tooLong‘=>‘密码请输入长度为6-22位字符‘‘tooShort‘=>‘密码请输入长度为6-22位字符‘),
17
18     //判断用户输入的是否是邮件
19     array(‘email‘,‘email‘,‘message‘=>‘邮箱格式错误‘),
20
21     //检查用户输入的密码是否是一样的
22     array(‘verifyPassword‘‘compare‘‘compareAttribute‘=>‘password‘‘message‘=>‘请再输入确认密码‘),
23
24     //检查用户是否同意协议条款
25     array(‘agree‘‘required‘‘requiredValue‘=>true,‘message‘=>‘请确认是否同意隐私权协议条款‘),
26
27     //判断是否是日期格式
28     array(‘created‘‘date‘‘format‘=>‘yyyy/MM/dd/ HH:mm:ss‘),
29
30     //判断是否包含输入的字符
31     array(‘superuser‘‘in‘‘range‘=> array(0, 1)),
32     
33     //正则验证器:       
34     array(‘name‘,‘match‘,‘pattern‘=>‘/^[a-z0-9\-_]+$/‘),
35     
36     //数字验证器:              
37     array(‘id‘‘numerical‘‘min‘=>1, ‘max‘=>10, ‘integerOnly‘=>true),
38     
39     //类型验证 integer,float,string,array,date,time,datetime                
40     array(‘created‘‘type‘‘datetime‘),
41     
42     //文件验证:       
43     array(‘filename‘‘file‘‘allowEmpty‘=>true, ‘types‘=>‘zip, rar, xls, pdf, ppt‘,‘tooLarge‘=>‘图片不要超过800K‘),
44
45     array(‘url‘
46         ‘file‘,    //定义为file类型 
47         ‘allowEmpty‘=>true,  
48         ‘types‘=>‘jpg,png,gif,doc,docx,pdf,xls,xlsx,zip,rar,ppt,pptx‘,   //上传文件的类型 
49         ‘maxSize‘=>1024*1024*10,    //上传大小限制,注意不是php.ini中的上传文件大小 
50         ‘tooLarge‘=>‘文件大于10M,上传失败!请上传小于10M的文件!‘
51     ),
52 );

More commonly used rules validation rule records in Yii

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.