IntegralValidator.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\enterprise\validate;
  3. use think\Validate;
  4. /**
  5. * Description of IntegralValidator
  6. * @author sgq
  7. */
  8. class IntegralValidator extends Validate {
  9. protected $rule = [
  10. "name" => "regex:/^[\x{4e00}-\x{9fa5}]+$/u",
  11. "card_type" => "between:1,3",
  12. "card_number" => "checkCardNumber",
  13. "phone" => "mobile",
  14. "email" => "email"
  15. ];
  16. protected $message = [
  17. "name.regex" => "姓名只能是中文",
  18. "card_type.between" => "不存在的证件类型,请在列表中选择",
  19. "phone.mobile" => "请填写正确的手机号",
  20. "email.email" => "电子邮箱格式错误"
  21. ];
  22. protected function checkCardNumber($value, $rule, $data = []) {
  23. if (!$data["card_type"]) {
  24. return "填写证件号码前请先选择证件类型";
  25. }
  26. if ($data["card_type"] == 1) {
  27. $num = strlen($value);
  28. switch ($num) {
  29. case 15:
  30. case 18:
  31. return \app\common\api\IdCardApi::isValid($value) ?: "身份证号码不合法";
  32. break;
  33. default:
  34. //return \app\common\api\IdCardApi::isValidExceptMainland($value) ?: "身份证号码不合法";
  35. break;
  36. }
  37. }
  38. return "身份证号码不合法";
  39. }
  40. }