AlGallaf
AlGallaf

Reputation: 635

Laravel Field Validation: Either 8 or 16 Digits is Allowed

I'm trying to validate a text field using Laravel's validation class. The same text field can either have exactly 8 digits or 16 digits. The below code did not work.

    $validationRules = [
        'number' => 'required|digits:8/16',
    ];

Upvotes: 1

Views: 396

Answers (1)

IvanY
IvanY

Reputation: 153

Try this

 $validationRules = [
    'number' => 'required|regex:/^(\d{8}|\d{16})$/',
 ];

Upvotes: 3

Related Questions