namespace App\Providers; use Illuminate\Support\ServiceProvider; use Validator; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { // validator extend phone Validator::extend(‘phone‘, function ($attribute, $value, $parameters) { if (preg_match(‘/^170/‘, $value)) { return false; } if (preg_match(‘/^1(3[0-9]|4[0-9]|5[012356789]|8[01256789]|7[0678])\d{8}$/‘, $value)) { return true; } return false; }, ‘手机号不正确‘); // \DB::listen(function($query) { // \Log::info($query->sql); // }); }
原文:http://www.cnblogs.com/smallyi/p/6970693.html