6
0
Fork 0

手机号码校验规则

release
李静 2021-11-23 16:46:03 +08:00
parent 9521551704
commit 4a8ee05688
1 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,30 @@
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class PhoneNumber implements Rule
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value): bool
{
return (bool) preg_match('/^1[3-9]\d{9}$/', $value);
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return '手机号码格式不正确';
}
}