MobileRule.php 855 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Validators\Rules;
  3. use Illuminate\Contracts\Validation\Rule;
  4. class MobileRule implements Rule
  5. {
  6. /**
  7. * Create a new rule instance.
  8. *
  9. * @return void
  10. */
  11. public function __construct()
  12. {
  13. //
  14. }
  15. /**
  16. * Determine if the validation rule passes.
  17. *
  18. * @param string $attribute
  19. * @param mixed $value
  20. * @return bool
  21. */
  22. public function passes($attribute, $value)
  23. {
  24. //手机验证:第一位是1,第二个是(2|3|4|5|6|7|8|9)中的一个,位数是11位.
  25. if (preg_match("/^1(2|3|4|5|6|7|8|9)\d{9}$/", $value)) {
  26. return true;
  27. }
  28. return false;
  29. }
  30. /**
  31. * Get the validation error message.
  32. *
  33. * @return string
  34. */
  35. public function message()
  36. {
  37. return '手机号码不正确';
  38. }
  39. }