Checking if the exact length of a numeric field is correct in laravel 5

I have a numeric field that I want to validate when filling 4 digits exactly.

like: 1234, 4567,1245

but these are invalid inputs: for example: 123, 346, 45m6, 34567

what i am trying:

'last4digits'             => 'numeric|between:4,4',

      

+3


source to share


1 answer


You are looking for a rule digits

. From the docs :

The field under validation must be numeric and must be of exact length.



'last4digits' => 'digits:4'

      

+4


source







All Articles