fredbradley/laravel-rule-nhs-number

A Laravel Validator Rule for checking the validity of a NHS Number

v2.0.2 2021-09-30 09:55 UTC

This package is auto-updated.

Last update: 2024-10-29 05:47:40 UTC


README

Latest Version on Packagist Build Status StyleCI Status Total Downloads

This is a Custom Laravel Rule for validating an NHS Number.

The NHS Number validation logic is written by Liam and found in a separate package, if you'd like to use it without Laravel's dependencies.

Installation

Install the package using Composer:

composer require fredbradley/laravel-rule-nhs-number

Laravel's service provider discover will automatically configure the service provider for you.

Using the Validator

After installation, the validator will be available for use directly in your validation rules.

'field_name' => 'nhsnumber'

Within the context of a form controller it would like like this:

return Validator::make($data, [
    'name' => 'required|string|max:255',
    'nhs_number' => 'required|string|nhsnumber'
]);

Using the Rule Object

NB: This is needed required to use with some form builders like Kris Forms

return Validator::make($data, [
    'name' => 'required|string|max:255',
    'nhs_number' => [
        'required',
        'string',
        new \FredBradley\NhsNumber\ValidateNhsNumber()
    ]
]);

Added bonus: Generators

Because we're using Liam's original code, I've added in a Generator helper class. Use this in your projects to generate valid random NHS Numbers:

echo \FredBradley\NhsNumber\Generator::nhsNumber();
// '9278462608'
echo \FredBradley\NhsNumber\Generator::nhsNumber(3);
// ['7448556886', '0372104223', '8416367035']

Contributing

At the moment the package is only available in English - due to the way the error message is displayed. If someone would like to contribute to make it translatable that would be nice of them.

👷 Credits

♻️ License

The MIT License (MIT). Please see the license file for more information.