Reputation: 10828
How to do input validation that a number must start with 0?
For example:
$rules = [
'full_name' => 'required|min:6',
'number' => 'required|numeric|min:5',
];
On the number
field, it is requred, must be numberic only and minimum of 5 digits. I also need to include rule that it must start with 0?
Upvotes: 2
Views: 6489
Reputation: 73251
You can try it with
substr(Input::get('number'), 0, 1);
as data field and the rule
'in:0'
But as php will cut leading zeros if you are transmitting the number as int, it will most likely be hard. If it's a number as string, it will work.
Upvotes: 1
Reputation: 2943
Use laravel regex:pattern
validator, inside an array (Issue with Laravel Rules & Regex (OR) operator) and a regex of something like this: /^[0][0-9]{4,}/
Upvotes: 4