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

laravel 自定义验证手机号

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:31:00
Original
2834 people have browsed it

<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>
Copy after login
Copy after login

以上是自定义的 验证规则

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>
Copy after login
Copy after login

以上是自定义的 验证规则

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

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template