Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 694
AngularAngularAngular Avatar asked Dec 23 '14 06:12

AngularAngularAngular


People also ask

How can I verify my phone number in laravel?

Validate Phone Number Laravel public function save(Request $request) { $validated = $request->validate([ phone_number=> 'required|numeric|min:10' ]); //If number passes validation, method will continue here. } In our save function we use the validate method provided by the Illuminate\Http\Request object.

How do you validate exact words in laravel?

I know of at least two ways. // option one: 'in' takes a comma-separated list of acceptable values $rules = [ 'field' => 'in:hello', ]; // option two: write a matching regular expression $rules = [ 'field' => 'regex:^hello$', ];

How can I validate my name in laravel?

php", to replace the :attribute name (input name) for a proper to read name (example: first_name > First name) . It seems very simple to use, but the validator doesn't show the "nice names". And the validation in the controller: $validation = Validator::make($input, $rules, $messages);


1 Answers

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.

like image 90
Damien Pirsy Avatar answered Oct 04 '22 13:10

Damien Pirsy