Member-only story

PhonePhone Validation in Laravel Using Abstract

Yoram Kornatzky
2 min readJun 17, 2024

Our sales events platform Auctibles, collects phone numbers for several purposes:

  1. Contact phone of sellers to be displayed to buyers
  2. Landline phone of sellers
  3. Mobile phone of sellers for coordination of deliveries
  4. Mobile phone of buyers for coordination of deliveries

Phone validation in Laravel is a crucial step for our sales events platform. It plays a significant role in ensuring smooth delivery coordination and reducing the risk of fraud.

We use validation rules, a practical feature of the PHP Laravel framework, to ensure reliable validation. This is where the Abstract comes in, enhancing the functionality of our platform.

The Validation Rule

We define a validation rule, AbstractPhoneValidation that receives two parameters:

  1. The type of phone number expected — mobile, landline, or an empty string when any type is expected,
  2. The country of the phone number — two letters ISO 3166–1 alpha-2 code

The rule uses our Abstract API key from the configuration file.

namespace App\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use

--

--

Yoram Kornatzky
Yoram Kornatzky

Written by Yoram Kornatzky

Entrepreneur, Auctibles: https://auctibles.com, 25 years of development experience, Ph.D. Computer Science

No responses yet