YII 表單驗(yàn)證守則大全
Jun 13, 2016 pm 12:27 PM
YII 表單驗(yàn)證規(guī)則大全
<?phpclass ContactForm extends CFormModel{ public $_id; public $contact;//聯(lián)系人 public $tel;//電話(huà) public $fax;//傳真 public $zipcode;//郵編 public $addr;//地址 public $mobile;//手機(jī) public $email;//郵箱 public $website;//網(wǎng)址 public $qq;//QQ public $msn;//MSN public function rules() { return array( array('contact','required','on'=>'edit','message'=>'聯(lián)系人必須填寫(xiě).'), array('contact','length','on'=>'edit','min'=>2,'max'=>10,'tooShort'=>'聯(lián)系人長(zhǎng)度請(qǐng)控制在2-10個(gè)字符.','tooLong'=>'聯(lián)系人長(zhǎng)度請(qǐng)控制在2-10個(gè)字符.'), array('tel', 'match','pattern' => '/^(\d{3}-|\d{4}-)(\d{8}|\d{7})?$/','message' => '請(qǐng)輸入正確的電話(huà)號(hào)碼.'), array('fax', 'match','pattern' => '/^(\d{3}-|\d{4}-)(\d{8}|\d{7})?$/','message' => '請(qǐng)輸入正確的傳真號(hào)碼.'), array('mobile', 'match','pattern' => '/^13[0-9]{1}[0-9]{8}$|15[0189]{1}[0-9]{8}$|189[0-9]{8}$/','message' => '請(qǐng)輸入正確的手機(jī)號(hào)碼.'), array('email','email','on'=>'edit','message'=>'郵箱輸入有誤.'), array('zipcode','required','on'=>'edit','message'=>'郵編必須填寫(xiě).'), array('zipcode','numerical','on'=>'edit','message'=>'郵編是6位數(shù)字.'), array('zipcode','length','on'=>'edit','min'=>6,'max'=>6,'tooShort'=>'郵編長(zhǎng)度為6位數(shù).','tooLong'=>'郵編長(zhǎng)度為6位數(shù).'), array('website','url','on'=>'edit','message'=>'網(wǎng)址輸入有誤.'), array('qq', 'match','pattern' => '/^[1-9]{1}[0-9]{4,11}$/','message' => '請(qǐng)輸入正確的QQ號(hào)碼.'), array('msn','email','on'=>'edit','message'=>'MSN輸入有誤.'), ); } }
完整示例:
public $password2;//非數(shù)據(jù)庫(kù)的字段,但是在view中需要用到 public $verify; //手機(jī)驗(yàn)證碼 public $fjg; //忘記號(hào)碼 /** * 映射數(shù)據(jù)庫(kù)表名 * @return string the associated database table name<br /><br /> * www.shouce.ren */ public function tableName() { return 'adm_user'; } /** * 驗(yàn)證規(guī)則 * @return array validation rules for model attributes. */ public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( //array('mobile_phone,name,status', 'required'), array('mobile_phone', 'unique'),//'message' => '該手機(jī)號(hào)已經(jīng)存在!' array('mobile_phone', 'match','pattern' => '/^(13|15|18)[0-9]{9}$/','message' => '請(qǐng)輸入正確的經(jīng)辦人手機(jī)號(hào)碼.'), //array('certificate_id', 'match','pattern' => '/(.jpg|.gif|.png|\d)$/','message' => '請(qǐng)重新選擇證書(shū)圖像并且后綴只能是jpg、gif、png格式.'), array('phone', 'match','pattern' => '/^(\d{3}-|\d{4}-)?(\d{8}|\d{7})?$/','message' => '請(qǐng)輸入正確的座機(jī)號(hào)碼.'), array('fax', 'match','pattern' => '/^(\d{3}-|\d{4}-)(\d{8}|\d{7})?$/','message' => '請(qǐng)輸入正確的傳真號(hào)碼.'), //array('email_address', 'match','pattern' => '/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/','message' => '請(qǐng)輸入正確的郵箱.'), array('email_address','email','message'=>'請(qǐng)輸入正確的郵箱.'), //驗(yàn)證密碼和確認(rèn)密碼 array("password2","compare","compareAttribute"=>"password","message"=>"兩次密碼不一致",'on'=>'register'), array("password2","compare","compareAttribute"=>"password","message"=>"兩次密碼不一致",'on'=>'regonter'), array('qq', 'match','pattern' => '/^[1-9]{1}[0-9]{4,11}$/','message' => '請(qǐng)輸入正確的QQ號(hào)碼.'), array('type,certificate_id,company_type, nationality,yyzz_id, status,level,create_by_id, create_time,update_time', 'numerical', 'integerOnly'=>true), array('verify', 'numerical', 'message' => '驗(yàn)證碼不正確','integerOnly'=>true), array('name,user_type,tuijianren', 'length', 'max'=>20), array('password', 'length', 'max'=>100), array('email_address,business', 'length', 'max'=>50), array('communication_address,money, yhzh,yhmc,industry, company, register_address,yhdh,shangbiao,zhuanli,gongshang', 'length', 'max'=>255), array('role_id','default', 'setOnEmpty'=>true, 'value'=>10), array('shangbiao','default', 'setOnEmpty'=>true, 'value'=>'0,0'), array('zhuanli','default', 'setOnEmpty'=>true, 'value'=>'0,0'), array('gongshang','default', 'setOnEmpty'=>true, 'value'=>'0,0'), array('password','default', 'setOnEmpty'=>true, 'value'=>'123456'), /*驗(yàn)證碼*/ array('verify','checkVerify', 'on'=>'register'), array('email_address','checkemail', 'on'=>'regonter'), // array('certificate_id', 'file','allowEmpty'=>true,// 'types'=>'jpg, gif, png, doc, txt',// 'maxSize'=>1024 * 1024 * 10, // 10MB// 'tooLarge'=>'文件大小不能超過(guò)10M!',// 'message'=>'請(qǐng)先上傳證書(shū)圖像.'// ), // The following rule is used by search(). // @todo Please remove those attributes that should not be searched. array('id,role_id,name, password,user_type, email_address,tuijianren,shangbiao,company_type,zhuanli,gongshang,money,yhzh,yhmc,yyzz_id,yhdh,type,level, phone, qq, mobile_phone, fax, communication_address, nationality, industry, company, business, register_address, certificate, status, create_by_id, create_time, update_time', 'safe', 'on'=>'search'), ); } /* * 手機(jī)驗(yàn)證碼校驗(yàn) */ public function checkVerify($attribute,$params) { $model=new Mess(); $d_title = $model->find(array('condition'=>'suij=:suij and tel=:tel and type>:type and time>:time','params'=>array(':suij'=>$this->verify,':tel'=>$this->mobile_phone,':type'=>0,':time'=>(time()-3600)),'select'=>array('id'))); //$d_title = $model->findByAttributes(array('suij'=>$this->verify,'tel'=>$this->mobile_phone),array('select'=>array('id'))); if($d_title['id']<1) { $this->addError('verify', "驗(yàn)證碼不正確。"); } else { if($this->password == $this->password2) { $model->updateAll(array('type'=>0),array('condition'=>'suij=:sj','params'=>array(':sj'=>$this->verify))); } } }
?

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Every year before Apple releases a new major version of iOS and macOS, users can download the beta version several months in advance and experience it first. Since the software is used by both the public and developers, Apple has launched developer and public versions, which are public beta versions of the developer beta version, for both. What is the difference between the developer version and the public version of iOS? Literally speaking, the developer version is a developer test version, and the public version is a public test version. The developer version and the public version target different audiences. The developer version is used by Apple for testing by developers. You need an Apple developer account to download and upgrade it.

vue3 uses element-plus to call the message environment: vue3+typescript+element-plus1. After the global introduction of element, element has added the global method $message in app.config.globalProperties, so you can use mounted(){(thisasany) directly in the optionsAPI. $message.success("this.$message");}2. In the compositionAPI, the setup method passes in two variables props and

Title: Example of using the Array.Sort function to sort an array in C# Text: In C#, array is a commonly used data structure, and it is often necessary to sort the array. C# provides the Array class, which has the Sort method to conveniently sort arrays. This article will demonstrate how to use the Array.Sort function in C# to sort an array and provide specific code examples. First, we need to understand the basic usage of the Array.Sort function. Array.So

When programming in PHP, we often need to merge arrays. PHP provides the array_merge() function to complete array merging, but when the same key exists in the array, this function will overwrite the original value. In order to solve this problem, PHP also provides an array_merge_recursive() function in the language, which can merge arrays and retain the values ??of the same keys, making the program design more flexible. array_merge

In PHP, there are many powerful array functions that can make array operations more convenient and faster. When we need to combine two arrays into an associative array, we can use PHP's array_combine function to achieve this operation. This function is actually used to combine the keys of one array as the values ??of another array into a new associative array. Next, we will explain how to use the array_combine function in PHP to combine two arrays into an associative array. Learn about array_comb

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:
