validating a numeric input's length in laravel 5

bobD picture bobD · Sep 16, 2016 · Viewed 72.4k times · Source

foo.blade.php

<input type="text" name="national-id" />

FooController.php

$rules = [
    'national-id' => 'required|size:10|numeric'
];

the national-id field should contain 10 digits and I actually expected the code above to validate this , but instead It will check If the national-id exactly equals to 10 or not ...

how can I validate the length of a numeric field?

Answer

Marcin Nabiałek picture Marcin Nabiałek · Sep 16, 2016

In fact you don't need to use digits_between rule. You can use digits rule so according to documentation it will be enough to use:

$rules = [
    'national-id' => 'required|digits:10'
];

without numeric rule because digits rule also verify if given value is numeric.