2 回答

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊
//自定義驗(yàn)證函數(shù)
protected function checkMobile($value)
{
# 01: 首先循環(huán)當(dāng)前數(shù)據(jù) 每一項(xiàng)的值(value)
# 02: 之后將該值賦給 變量mobile
# 03: 之后使用寫驗(yàn)證規(guī)則和錯(cuò)誤信息
# 04: 之后將錯(cuò)誤信息給$this->message();
# 05: 最后驗(yàn)證 $this->check(驗(yàn)證數(shù)據(jù),驗(yàn)證規(guī)則);
# 06: 最后判斷 如何為false 就返回錯(cuò)誤信息 $this->getError();
foreach ($value as $item) {
$data['mobile'] = $item;
$rules = [
'mobile' => 'require|mobile',
];
$message = [
'mobile.require' => '手機(jī)號(hào)碼不得為空!',
'mobile.mobile' => '手機(jī)號(hào)碼格式錯(cuò)誤!',
];
if (false === $this->message($message)->check($data, $rules)) {
return $this->getError();
} else {
return true;
}
}
}
使用的時(shí)候:
protected $rule = [ 'mobile' => 'require|checkMobile', ];
數(shù)據(jù)是:
$data = [ [ 'mobile'=> ['手機(jī)號(hào)碼1','手機(jī)號(hào)碼2'], ]; ];
- 2 回答
- 0 關(guān)注
- 2538 瀏覽
添加回答
舉報(bào)