<?php

namespace App\Providers;

use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
use Illuminate\Validation\Validator as Validate;

class ValidateServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        //手机号验证
        Validator::extend('mobile', function ($attribute, $value, $parameters, Validate $validator) {
            return $validator->validateRegex($attribute, $value, ['/^((\+|00)86)?1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/']);
        });

        //姓名验证
        Validator::extend('name', function ($attribute, $value, $parameters, Validate $validator) {
            return $validator->validateRegex($attribute, $value, ['/^[\x{4E00}-\x{9FA5}A-Za-z\s]+(·[\x{4E00}-\x{9FA5}A-Za-z]+)*$/u']);
        });

        //银行卡号
        Validator::extend('bank_num', function ($attribute, $value, $parameters, Validate $validator) {
            return $validator->validateRegex($attribute, $value, ['/^([1-9]{1})(\d{15}|\d{18})$/']);
        });


    }
}
