欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Laravel Rule Validation for Numbers 验证数字 有大用

I have the following Rule :

'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 Digit to Maximum 5 Digit and

Lno Should be a Digit only with Min 2 Digit

shareimprove this questionedited Dec 23 '14 at 6:20asked Dec 23 '14 at 6:02AngularAngularAngular73931028

1 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'];

整数的话 当然可以使用 

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

再加个 not_in:2  这样就不等于最小值 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.

shareimprove this answeranswered Dec 23 '14 at 6:20Damien Pirsy21.3k65171

3 Just adding one more validation type digits:value.The field under validation must be numeric and must have an exact length of value.[laravel.com/docs/5.0/validation#rule-digits] – Bugfixer Jul 25 '16 at 6:20 

来自  https://stackoverflow.com/questions/27614936/laravel-rule-validation-for-numbers

普通分类: