I'll-Be-Back
I'll-Be-Back

Reputation: 10828

Laravel Validation - number must start with 0 (zero)

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

Answers (2)

baao
baao

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

cen
cen

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

Related Questions