Ayman Hussein
Ayman Hussein

Reputation: 3857

validation on exact length of numeric field in laravel 5

I have numeric field i want to validate on exact fill 4 digits.

like: 1234, 4567,1245

but these invalid inputs: like: 123, 346, 45m6, 34567

what I am trying:

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

Upvotes: 15

Views: 14746

Answers (2)

CodeToLife
CodeToLife

Reputation: 4151

in general case ,say, for a string with arbitrary characters:

'last_not_only_4_digits' => 'size:4'

Upvotes: 13

lukasgeiter
lukasgeiter

Reputation: 152890

You are looking for the digits rule. From the docs:

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

'last4digits' => 'digits:4'

Upvotes: 26

Related Questions