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
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.
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$', ];
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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With