2

In Laravel, its easy to validate numeric inputs-

$rules = array('numericInput' => 'numeric');

But not sure, how to validate a numeric array. What can be the rule for that. Or is it even possible by Laravel's Validator class?

For e.g-

This HTML form submits multiple Select item to a laravel service

<form .....>
  <select multiple="multiple" name="objectIdArr[]" >
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
  </select>
</form>

What Laravel gets-

( [input] => Array ( [objectIdArr] => Array ( [0] => 1 [1] => 3 [2] => 5 ))

what can be the rule!

Please suggest

1 Answer 1

0

Laravel 3.x's validator doesn't handle arrays unfortunately as it expects each unique name to be a string.

You could however extend the validator class as a library (follow the docs for a decent example) and allow your extended class to recieve an array that then is broken out into strings and validated, if any of the strings fail validation the validator returns a failure with your custom message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.