Validation alphabet and numeric value

what is regex for validation if value have both alphabet or numeric value ? thanks

johanesarnold
johanesarnold
  • 1 month ago

There is a rule for this already: https://laravel.com/docs/5.4/validation#rule-alpha-num

@gpluess is give the correct answer but you can use 'alpha_num' like:

public function rules()
{
       return [
           'name'    =>'required',
           'username'=>'required|alpha_num',
       ];
}

Hope this work for you!

@saurabhd @gpluess thanks for replying, i mean have at least one character and one numeric

This validation code is use in your validation script

public function rules()
{
      return [
          'name'    =>'required',
          'username'=>'required|regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$/,
      ];
}

Hope this work for you.