njoguamos/laravel-kenya-mobile

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

v2.1.0 2024-12-09 06:39 UTC

This package is auto-updated.

Last update: 2024-12-09 06:40:00 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. You can either validate phone number with 9 or 10 digits such as 700325008 or 0700325008 or validate full phone number such as 254700325008.

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.

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\KenyaMobileFullRule;
use NjoguAmos\KeMobile\KenyaMobileRule;
use Illuminate\Foundation\Http\FormRequest;

class RegisterUserRequest extends FormRequest
{
    /** @return array<string, mixed> */
    public function rules(): array
    {
        return [
            // ... other rules
            // Validate phone number with 9 or 10 digits
            'phone'    => ['nullable', new KenyaMobileRule(),'unique:users,phone'],
            // Or validate full phone number
            'full_phone'    => ['nullable', new KenyaMobileFullRule(),'unique:users,full_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.