TP验证规则Validate

Posted camg

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TP验证规则Validate相关的知识,希望对你有一定的参考价值。

use thinkValidate;

<?php
namespace appcommonmodel;

use thinkValidate;
use thinkDb;

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的主要内容,如果未能解决你的问题,请参考以下文章

TP5验证规则使用

tp5服务器验证案例

TP自动验证密码范围

tp框架表单验证 及ajax

案例17-validate自定义校验规则校验验证码是否输入正确

Tp5 独立验证器