Laravel Validation custom message

后端 未结 1 1447
伪装坚强ぢ
伪装坚强ぢ 2020-12-30 05:39

I am facing a problem with laravel custom validation message, here is what I have:

$rules = [
    \'first_name\'            => \'required|alpha|min:2\',
          


        
相关标签:
1条回答
  • 2020-12-30 06:20

    Here is the way to do it , just instead of using 'regex' , use 'phone.regex'

    $rules = [
        'first_name'            => 'required|alpha|min:2',
        'last_name'             => 'required|alpha|min:2',
        'email'                 => 'required|email|unique:users,email,' . Input::get('id') . ',id',
        'password'              => 'alpha_num|between:6,12|confirmed',
        'password_confirmation' => 'alpha_num|between:6,12',
        'address'               => 'regex:/^[a-z0-9- ]+$/i|min:2',
        'city'                  => 'alpha|min:2',
        'state'                 => 'alpha|min:2|max:2',
        'zip'                   => 'numeric|min:5|max:5',
        'phone'                 => 'regex:/^\d{3}\-\d{3}\-\d{4}$/',
    ];
    $messages = [
        'unique'        => 'The :attribute already been registered.',
        'phone.regex'   => 'The :attribute number is invalid , accepted format: xxx-xxx-xxxx',
        'address.regex' => 'The :attribute format is invalid.',
    ];
    
    0 讨论(0)
提交回复
热议问题