njoguamos/laravel-kenya-mobile

A rule for validating Kenya mobile number in a Laravel application.

v1.2.1 2024-03-02 08:14 UTC

This package is auto-updated.

Last update: 2024-10-12 06:43:06 UTC


README

Art work

Validate Kenyan Mobile Phone

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A rule for validating Kenyan mobile number.

1. Why use this package

  1. Save time from implementing your own validation rule.
  2. Tested with phone number approved by Communications Authority of Kenya supported.

Info This package assumed that the phone number is either a 9 digit e.g 700325008 or 10 digit 0700325008. Number with leading zero (0) should be casted into an (int) before storing in a database. It also assumed that you will store the prefix +254 in different column or table.

2. Installation

You can install the package via composer:

composer require njoguamos/laravel-kenya-mobile

3. Usage

3.1 Inside a form request

<?php

namespace App\Http\Requests;

use NjoguAmos\KeMobile\KenyaMobileRule;
use Illuminate\Foundation\Http\FormRequest;

class RegisterUserRequest extends FormRequest
{
    /** @return array<string, mixed> */
    public function rules(): array
    {
        return [
            // ... other rules
            'phone'    => ['nullable', new KenyaMobileRule(),'unique:users,phone'],
        ];
    }
}

3.2 Supported mobile numbers

4. Testing

composer test

5. Changelog

Please see RELEASES for more information what has changed recently.

6. Contributing

Please see CONTRIBUTING for details.

7. Security Vulnerabilities

If you discover any security related issues, please email njoguamos@gmail.com instead of using the issue tracker.

8. Credits

9. License

The MIT License (MIT). Please see License File for more information.