1

Please help me I am new in laravel. I set form validation like first two characters are alphabet and last four character numeric. Example AB1234

waqar
  • 33
  • 5

2 Answers2

1

As comments say, you can do this by regex:

$validated = $request->validate([
    'some_col' => ['string', 'regex:/^[A-Z]{2}[0-9]{4}$/'],
    // other rule
]);

According to docs, this rule use preg_match so you should follow the same formatting required by preg_match. Don't forget to use array to specify rules (just like example code).

hms5232
  • 323
  • 1
  • 6
0

Use Regular expression in the Validator,

return Validator::make($data, [
    'your_input' => [
        'required',
        'regex:/^[a-zA-Z]{2}[0-9]{4}+$/',
    ]
]);

you need to add ^ and $ on regex to make sure it match First 2 and 4 End

adam
  • 347
  • 2
  • 7