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.
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.
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'
]);
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()
]
]);
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']
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.
- Fred Bradley for the Laravel-ication of the validator
- Liam Hammett for the original package
- Peter Fisher for the original class
- All Contributors
The MIT License (MIT). Please see the license file for more information.