123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace App\Base\Validation;
- use Illuminate\Contracts\Validation\Rule;
- class Phone implements Rule
- {
- /**
- * Create a new rule instance.
- *
- * @return void
- */
- public function __construct()
- {
- //
- }
- /**
- * Determine if the validation rule passes.
- *
- * @param string $attribute
- * @param mixed $value
- * @return bool
- */
- public function passes($attribute, $value)
- {
- if (strlen($value) == 11) {
- $mobileRegex = '/^1[3-9]\d{9}$/';
- if (preg_match($mobileRegex, $value)) {
- return true;
- } else {
- return false;
- }
- }
- return false;
- }
- /**
- * Get the validation error message.
- *
- * @return string
- */
- public function message()
- {
- return ':attribute 必须是手机号';
- }
- }
|