yii表单的各种验证

/验证规则详细配置
 public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('username', 'required' ,'message'=>'用户名必须填写'),
//            array('username', 'required' ,'requiredValue'=>'abc','message'=>'用户名值必须为abc'),
//            array('username', 'required','requiredValue'=>'hello', 'message'=>'用户名值必须为hello'),
//            array('username', 'required', 'on' => 'register', 'message' => '用户名值必须填写'),
//            array('username', 'test'),
            
            
            array('password', 'required', 'message'=>'密码必须填写'),
//            array('password', 'checkme'),
            
            array('password2', 'required', 'message'=>'请输入确认密码'),
            array('password2', 'compare', 'compareAttribute'=>'password', 'message'=>'两次输入密码必须一致','on'=>'register'),
            
            
            array('telphone','match', 'allowEmpty'=>false, 'pattern'=>'/[13]\d{9}/','message'=> '手机号码必须是13开始的数字'),
            
            
//            array('user_email','email',  'message'=>'请匹配正确的电子邮箱'),
            
            array('username', 'unique', 'message'=>'用户名已经占用'),
            
            
            array('address', 'length', 'allowEmpty'=>false, 'max'=>'20', 'min'=>'5', 'tooLong'=>'太多了', 'tooShort'=>'太少了'),
            
            
            array('user_xueli', 'in', 'range'=>array(1,2,3,4),  'message'=>'学历必须选择'),
            
            array('user_age', 'numerical', 'allowEmpty'=>false, 'integerOnly'=>true, 'max'=>150, 'min'=>1, 'tooBig'=>'太高了', 'tooSmall'=>'太小了', 'message'=>'年龄必须是1-150之间的整数'),
            
            array('birthday', 'date', 'allowEmpty'=>false, 'format'=>'MM-dd-yyyy',  'message'=>'出生日期格式不正确MM-dd-yyyy'),

            
            array('user_email', 'safe'),
        );
    }

 

posted @ 2014-06-06 17:20  scrit  阅读(475)  评论(0编辑  收藏  举报