| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Providers;
- use Illuminate\Support\Facades\Validator;
- use Illuminate\Support\ServiceProvider;
- class AppServiceProvider extends ServiceProvider
- {
- /**
- * Register any application services.
- *
- * @return void
- */
- public function register()
- {
- //
- \DB::listen(function ($query) {
- $bindings = $query->bindings;
- $sql = $query->sql;
- foreach ($bindings as $replace) {
- $value = is_numeric($replace) ? $replace : "'" . $replace . "'";
- $sql = preg_replace('/\?/', $value, $sql, 1);
- }
- });
- }
- /**
- * Bootstrap any application services.
- *
- * @return void
- */
- public function boot()
- {
- //验证手机号码
- Validator::extend('mobile', function ($attribute, $value, $parameters, $validator) {
- // 返回true/false
- $reg='/^1[3-9]\d{9}$/';
- return preg_match($reg,$value);
- });
- // 身份证号码
- Validator::extend('idcard', function ($attribute, $value, $parameters, $validator) {
- // 返回true/false
- $reg='/(^\d{15}$)|(^\d{17}([0-9]|X))$/isu';
- return preg_match($reg,$value);
- });
- Validator::extend('username', function ($attribute, $value, $parameters, $validator) {
- // 返回true/false
- $reg='/^1[3-9]\d{9}$/';
- $reg1='/^[0-9a-zA-Z]+@(([0-9a-zA-Z]+)[.])+[a-z]{2,4}$/i';
- return preg_match($reg,$value) || preg_match($reg1,$value);
- });
- Validator::extend('realname', function ($attribute, $value, $parameters, $validator) {
- // 返回true/false
- $reg='/^[\u4e00-\u9fa5]{2,5}$/';
- return preg_match($reg,$value);
- });
- }
- }
|