Back

Validation alphabet and numeric value


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

gpluess replied 8 months ago

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

saurabhd replied 8 months ago

@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!

johanesarnold replied 8 months ago

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

saurabhd replied 8 months ago Solution

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.


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us