yii rules验证示例总结_PHP教程

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

yii rules验证示例总结

yii常见字段验证示例总结。

<?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

您可能感兴趣的文章

  • Yii rules常用验证规则备忘
  • Yii框架Yiiapp()的理解
  • Yii framework框架之模块开发分析
  • yii框架如何配置默认controller与action
  • Yii中validator之safe用法
  • Yii查看(输出)当前页面执行的sql语句
  • yii model层操作总结
  • Yii CDbCriteria的常用方法总结

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1058851.htmlTechArticleyii rules验证示例总结 yii常见字段验证示例总结。 ?phpclass ContactForm extends CFormModel{ public $id; public $contact;//联系人 public $tel;//电话 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!