Home >Backend Development >PHP Tutorial >laravel 自定义验证手机号

laravel 自定义验证手机号

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:31:002835browse

<code> public function rules()
 {
                $rules = [
                    'name'               => 'unique:merchants,name,'.$id.',id',
                    'mobile'             => 'required|numeric|min:10|max:10',
                    'dist_name'          => 'required',
                    'fare'               => 'sometimes|numeric',
                    'full_price'         => 'sometimes|numeric',
                    'city'               => 'required',
                    'address'            => 'required',
                ];
 }
</code>

以上是自定义的 验证规则

laravel 没有验证手机号的 ,添加一个验证规则 在 当前页面 怎么写呢

回复内容:

<code> public function rules()
 {
                $rules = [
                    'name'               => 'unique:merchants,name,'.$id.',id',
                    'mobile'             => 'required|numeric|min:10|max:10',
                    'dist_name'          => 'required',
                    'fare'               => 'sometimes|numeric',
                    'full_price'         => 'sometimes|numeric',
                    'city'               => 'required',
                    'address'            => 'required',
                ];
 }
</code>

以上是自定义的 验证规则

laravel 没有验证手机号的 ,添加一个验证规则 在 当前页面 怎么写呢

'phone'=>'regex:/^1[34578][0-9]{9}$/'

/^13\d{9}$|^14\d{9}$|^15\d{9}$|^17\d{9}$|^18\d{9}$/

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn