Phone.php 742 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Rules;
  3. use Illuminate\Contracts\Validation\Rule;
  4. /**
  5. * 检测邮件验证码
  6. *
  7. * @author 刘相欣
  8. *
  9. */
  10. class Phone implements Rule{
  11. /**
  12. * 判断是否通过验证规则
  13. *
  14. * @param string $attribute
  15. * @param mixed $value
  16. * @return bool
  17. */
  18. public function passes($attribute, $value)
  19. {
  20. // 解码
  21. $result = preg_match('/^1[3-9]\d{9}$/',$value);
  22. // 错误提示
  23. return $result ? true : false;
  24. }
  25. /**
  26. * 获取校验错误信息
  27. *
  28. * @return string
  29. */
  30. public function message()
  31. {
  32. return trans('validation.phone');
  33. }
  34. }