Home > Backend Development > PHP Tutorial > Summary of yii rules verification examples_PHP tutorial

Summary of yii rules verification examples_PHP tutorial

WBOY
Release: 2016-07-12 09:07:54
Original
903 people have browsed it

Yii rules validation example summary

Yii common field validation example summary.

<?php
class ContactForm extends CFormModel{
    public $id;
    public $contact;//联系人
    public $tel;//电话
    public $fax;//传真
    public $zipcode;//邮编
    public $addr;//地址
    public $mobile;//手机
    public $email;//邮箱
    public $website;//网址
    public $qq;//QQ
    public $msn;//MSN
	public $add_time;//添加时间
    public function rules(){
        return array(
			array('id,add_time','numerical','integerOnly'=>true),//这些字段必须为数字
			//关于safe的理解可参考:http://www.phpernote.com/php-template-framework/1163.html
			array('contact,tel,fax,zipcode,addr,mobile,email,website,qq,msn,add_time','safe')
            array('contact','required','on'=>'edit','message'=>'联系人必须填写.'),
            array('contact','length','on'=>'edit','min'=>2,'max'=>10,'tooShort'=>'联系人长度请控制在2-10个字符.','tooLong'=>'联系人长度请控制在2-10个字符.'),
            array('tel','match','pattern'=>'/^(\d{3}-|\d{4}-)(\d{8}|\d{7})?$/','message'=>'请输入正确的电话号码.'),
            array('fax','match','pattern'=>'/^(\d{3}-|\d{4}-)(\d{8}|\d{7})?$/','message'=>'请输入正确的传真号码.'),
            array('mobile','match','pattern'=>'/^13[0-9]{1}[0-9]{8}$|15[0189]{1}[0-9]{8}$|189[0-9]{8}$/','message'=>'请输入正确的手机号码.'),
            array('email','email','on'=>'edit','message'=>'邮箱输入有误.'),
            array('zipcode','required','on'=>'edit','message'=>'邮编必须填写.'),
            array('zipcode','numerical','on'=>'edit','message'=>'邮编是6位数字.'),
            array('zipcode','length','on'=>'edit','min'=>6,'max'=>6,'tooShort'=>'邮编长度为6位数.','tooLong'=>'邮编长度为6位数.'),
            array('website','url','on'=>'edit','message'=>'网址输入有误.'),
            array('qq','match','pattern'=>'/^[1-9]{1}[0-9]{4,11}$/','message'=>'请输入正确的QQ号码.'),
            array('msn','email','on'=>'edit','message'=>'MSN输入有误.'),
        );
    }
}
Copy after login

Articles you may be interested in

  • Yii rules common verification rules memo
  • Understanding of Yii framework Yiiapp()
  • Yii framework Module development analysis
  • How to configure the default controller and action in the yii framework
  • Safe usage of validator in Yii
  • Yii views (outputs) the sql statements executed on the current page
  • Summary of yii model layer operations
  • Summary of common methods of Yii CDbCriteria

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1058851.htmlTechArticleyii rules validation example summary yii common field validation example summary. ?phpclass ContactForm extends CFormModel{ public $id; public $contact;//Contact public $tel;//Telephone public $fax;...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template