码迷,mamicode.com
首页 > 其他好文 > 详细

TP验证规则Validate

时间:2019-12-06 23:23:38      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:this   nbsp   prot   func   voice   type   类型   turn   erro   

use think\Validate;

<?php
namespace app\common\model;

use think\Validate;
use think\Db;

class InvoiceRecords extends BaseModel
{
    protected $table = ‘t_invoice_record‘;

    protected $rule = [
        ‘type‘  => ‘in:1,2‘,
        ‘invoice_tel‘  => ‘mobile‘,
        ‘email‘  => ‘email‘,

    ];
    protected $message = [
        ‘type‘ => ‘开票类型错误‘,
        ‘invoice_tel‘ => ‘手机号错误‘,
        ‘email‘ => ‘邮箱格式错误‘,

    ];

    public function addInfoData($member_id, $type, $money, $invoice_name, $invoice_tel, $email, $taxpayer_number, $id)
    {
        $data = [
            ‘type‘ => $type,
            ‘invoice_tel‘ => $invoice_tel,
            ‘email‘ => $email,
        ];
        $validate = new Validate($this->rule, $this->message);
        if (!$validate->check($data)) {
            return [‘code‘ => 400, ‘msg‘ => $validate->getError()];
        }
    }
}

 

TP验证规则Validate

标签:this   nbsp   prot   func   voice   type   类型   turn   erro   

原文地址:https://www.cnblogs.com/camg/p/11999978.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!