Memo for commonly used verification rules for Yii rules
Record the more commonly used rules verification rules in Yii and study them carefully later.
return array( //必须填写 array('email, username, password,agree,verifyPassword,verifyCode', 'required'), //检查用户名是否重复 array('email','unique','message'=>'用户名已占用'), //用户输入最大的字符限制 array('email, username', 'length', 'max'=>64), //限制用户最小长度和最大长度 array('username', 'length', 'max'=>7, 'min'=>2, 'tooLong'=>'用户名请输入长度为4-14个字符', 'tooShort'=>'用户名请输入长度为2-7个字'), //限制密码最小长度和最大长度 array('password', 'length', 'max'=>22, 'min'=>6, 'tooLong'=>'密码请输入长度为6-22位字符', 'tooShort'=>'密码请输入长度为6-22位字符'), //判断用户输入的是否是邮件 array('email','email','message'=>'邮箱格式错误'), //检查用户输入的密码是否是一样的 array('verifyPassword', 'compare', 'compareAttribute'=>'password', 'message'=>'请再输入确认密码'), //检查用户是否同意协议条款 array('agree', 'required', 'requiredValue'=>true,'message'=>'请确认是否同意隐私权协议条款'), //判断是否是日期格式 array('created', 'date', 'format'=>'yyyy/MM/dd/ HH:mm:ss'), //判断是否包含输入的字符 array('superuser', 'in', 'range' => array(0, 1)), //正则验证器: array('name','match','pattern'=>'/^[a-z0-9\-_]+$/'), //数字验证器: array('id', 'numerical', 'min'=>1, 'max'=>10, 'integerOnly'=>true), //类型验证 integer,float,string,array,date,time,datetime array('created', 'type', 'datetime'), //文件验证: array('filename', 'file', 'allowEmpty'=>true, 'types'=>'zip, rar, xls, pdf, ppt','tooLarge'=>'图片不要超过800K'), array('url', 'file', //定义为file类型 'allowEmpty'=>true, 'types'=>'jpg,png,gif,doc,docx,pdf,xls,xlsx,zip,rar,ppt,pptx', //上传文件的类型 'maxSize'=>1024*1024*10, //上传大小限制,注意不是php.ini中的上传文件大小 'tooLarge'=>'文件大于10M,上传失败!请上传小于10M的文件!' ), );
Articles you may be interested in
- Solution to the DedeTag Engine Create File False error in dedeCMS
- php uses filter function to verify email, url and ip Address method
- Unix/Linux graphic tutorial of commonly used basic commands
- PHP function to extract the birthday date in the ID number and verify whether it is a minor
- JS acquisition The code of the button, how to block the user's button in Js, Js to get the ASII code corresponding to the user's button (compatible with all browsers)
- A very practical php pop-up error warning function
- Due to its configuration information ( ) in the registry is incomplete or corrupted, and Windows cannot start this hardware device. (Code 19) Solution
- Thinkphp automatic verification and autofill invalid solution

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6
Visual web development tools

Atom editor mac version download
The most popular open source editor
