TP5 多条件正则
<?php
namespace app\admin\validate;
use think\Validate;
class Mail extends Validate
{
/**
* 验证规则
*/
protected $rule = [
'test_name'=>'require|unique:表名,test_name^id'//验证唯一性
//test_name和ID转移的SQL 为:select 'id' form 表明 where `test_name`='传入的字符串' AND `id` <> '传入的ID值'
‘test_mobile’=>'checkMobile'//自定义验证规则
];
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
/**自定义验证方法
* @param $value 选中的值 例:130***1234
* @param $rule 规则 可以不写此参数
* @param $data 条件,例:$data['mobile'] = ['130***1234','188***5220','155***3210']
* @return bool|string
*/
protected function checkMobile($value, $rule, $data)
{
if (条件) {//条件为真
return true;
} else { //条件为假
return '错误信息';
}
}
}
?>