Php – Laravel rule validation for numbers

laravellaravel-4PHP

I have the following rules :

'Fno' => 'digits:10'
'Lno' => 'min:2|max5'  // this seems invalid

But how to have the rule that

Fno should be a digit with minimum 2 digits to maximum 5 digits and

Lno should be a digit only with min 2 digits

Best Answer

If I correctly got what you want:

$rules = ['Fno' => 'digits_between:2,5', 'Lno' => 'numeric|min:2'];

or

$rules = ['Fno' => 'numeric|min:2|max:5', 'Lno' => 'numeric|min:2'];

For all the available rules: http://laravel.com/docs/4.2/validation#available-validation-rules

digits_between :min,max

The field under validation must have a length between the given min and max.

numeric

The field under validation must have a numeric value.

max:value

The field under validation must be less than or equal to a maximum value. Strings, numerics, and files are evaluated in the same fashion as the size rule.

min:value

The field under validation must have a minimum value. Strings, numerics, and files are evaluated in the same fashion as the size rule.