{"action":"opened","issue":{"url":"https://api.github.com/repos/wangming1993/issues/issues/10","labels_url":"https://api.github.com/repos/wangming1993/issues/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/wangming1993/issues/issues/10/comments","events_url":"https://api.github.com/repos/wangming1993/issues/issues/10/events","html_url":"https://github.com/wangming1993/issues/issues/10","id":114392193,"number":10,"title":"Yii2 rules常用规则  核心验证器","user":{"login":"wangming1993","id":5611286,"avatar_url":"https://avatars.githubusercontent.com/u/5611286?v=3","gravatar_id":"","url":"https://api.github.com/users/wangming1993","html_url":"https://github.com/wangming1993","followers_url":"https://api.github.com/users/wangming1993/followers","following_url":"https://api.github.com/users/wangming1993/following{/other_user}","gists_url":"https://api.github.com/users/wangming1993/gists{/gist_id}","starred_url":"https://api.github.com/users/wangming1993/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wangming1993/subscriptions","organizations_url":"https://api.github.com/users/wangming1993/orgs","repos_url":"https://api.github.com/users/wangming1993/repos","events_url":"https://api.github.com/users/wangming1993/events{/privacy}","received_events_url":"https://api.github.com/users/wangming1993/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-10-31T06:49:58Z","updated_at":"2015-10-31T06:49:58Z","closed_at":null,"body":"[***yii2 rules 核心验证器***](http://www.yiichina.com/doc/guide/2.0/tutorial-core-validators)\r\n\r\n```php\r\npublic function rules()\r\n{\r\nreturn array(\r\n//必须填写\r\narray('email, username, password,agree,verifyPassword,verifyCode', 'required'),\r\n//检查用户名是否重复\r\narray('email','unique','message'=&gt;'用户名已占用'),\r\n//用户输入最大的字符限制\r\narray('email, username', 'length', 'max'=&gt;64),\r\n//限制用户最小长度和最大长度\r\narray('username', 'length', 'max'=&gt;7, 'min'=&gt;2, 'tooLong'=&gt;'用户名请输入长度为4-14个字符', 'tooShort'=&gt;'用户名请输入长度为2-7个字'),\r\n//限制密码最小长度和最大长度\r\narray('password', 'length', 'max'=&gt;22, 'min'=&gt;6, 'tooLong'=&gt;'密码请输入长度为6-22位字符', 'tooShort'=&gt;'密码请输入长度为6-22位字符'),\r\n//判断用户输入的是否是邮件\r\narray('email','email','message'=&gt;'邮箱格式错误'),\r\n//检查用户输入的密码是否是一样的\r\narray('verifyPassword', 'compare', 'compareAttribute'=&gt;'password', 'message'=&gt;'请再输入确认密码'),\r\n//检查用户是否同意协议条款\r\narray('agree', 'required', 'requiredValue'=&gt;true,'message'=&gt;'请确认是否同意隐私权协议条款'),\r\n//判断是否是日期格式\r\narray('created', 'date', 'format'=&gt;'yyyy/MM/dd/ HH:mm:ss'),\r\n//判断是否包含输入的字符\r\narray('superuser', 'in', 'range' =&gt; array(0, 1)),\r\n//正则验证器：\r\narray('name','match','pattern'=&gt;'/^[a-z0-9\\-_]+$/'),\r\n//数字验证器：\r\narray('id', 'numerical', 'min'=&gt;1, 'max'=&gt;10, 'integerOnly'=&gt;true),\r\n//类型验证 integer,float,string,array,date,time,datetime\r\narray('created', 'type', 'datetime'),\r\n//文件验证：\r\narray('filename', 'file', 'allowEmpty'=&gt;true, 'types'=&gt;'zip, rar, xls, pdf, ppt','tooLarge'=&gt;'图片不要超过800K'),\r\narray('url',\r\n'file', //定义为file类型\r\n'allowEmpty'=&gt;true,\r\n'types'=&gt;'jpg,png,gif,doc,docx,pdf,xls,xlsx,zip,rar,ppt,pptx', //上传文件的类型\r\n'maxSize'=&gt;1024*1024*10, //上传大小限制，注意不是php.ini中的上传文件大小\r\n'tooLarge'=&gt;'文件大于10M，上传失败！请上传小于10M的文件！'\r\n),\r\n} );\r\n\r\n```"}}