{"id":42734707,"url":"https://github.com/imliam/php-nhs-number","last_synced_at":"2026-01-29T17:59:55.770Z","repository":{"id":54815328,"uuid":"141941035","full_name":"imliam/php-nhs-number","owner":"imliam","description":"Utility class to validate, format and generate NHS numbers.","archived":false,"fork":false,"pushed_at":"2025-03-09T16:44:22.000Z","size":18,"stargazers_count":2,"open_issues_count":3,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-22T23:37:23.441Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imliam.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-23T00:12:09.000Z","updated_at":"2025-04-09T13:06:49.000Z","dependencies_parsed_at":"2022-08-14T03:40:34.667Z","dependency_job_id":null,"html_url":"https://github.com/imliam/php-nhs-number","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/imliam/php-nhs-number","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imliam%2Fphp-nhs-number","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imliam%2Fphp-nhs-number/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imliam%2Fphp-nhs-number/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imliam%2Fphp-nhs-number/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imliam","download_url":"https://codeload.github.com/imliam/php-nhs-number/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imliam%2Fphp-nhs-number/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28882009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-29T16:41:59.663Z","status":"ssl_error","status_checked_at":"2026-01-29T16:39:39.641Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-29T17:59:52.547Z","updated_at":"2026-01-29T17:59:55.764Z","avatar_url":"https://github.com/imliam.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NHS Numbers\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/imliam/php-nhs-number.svg)](https://packagist.org/packages/imliam/php-nhs-number)\n[![Build Status](https://img.shields.io/travis/imliam/php-nhs-number.svg)](https://travis-ci.org/imliam/php-nhs-number)\n![Code Quality](https://img.shields.io/scrutinizer/g/imliam/php-nhs-number.svg)\n![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/imliam/php-nhs-number.svg)\n[![Total Downloads](https://img.shields.io/packagist/dt/imliam/php-nhs-number.svg)](https://packagist.org/packages/imliam/php-nhs-number)\n[![License](https://img.shields.io/github/license/imliam/php-nhs-number.svg)](LICENSE.md)\n\nUtility class to validate, format and generate NHS numbers.\n\n\u003c!-- TOC --\u003e\n\n- [NHS Numbers](#nhs-numbers)\n    - [🤔 F.A.Q.](#🤔-faq)\n        - [What is an NHS number?](#what-is-an-nhs-number)\n        - [How do you validate an NHS number?](#how-do-you-validate-an-nhs-number)\n    - [💾 Installation](#💾-installation)\n    - [📝 Usage](#📝-usage)\n    - [✅ Testing](#✅-testing)\n    - [🔖 Changelog](#🔖-changelog)\n    - [⬆️ Upgrading](#⬆️-upgrading)\n    - [🎉 Contributing](#🎉-contributing)\n        - [🔒 Security](#🔒-security)\n    - [👷 Credits](#👷-credits)\n    - [♻️ License](#♻️-license)\n\n\u003c!-- /TOC --\u003e\n\n## 🤔 F.A.Q.\n\n### What is an NHS number?\n\nAn \"NHS number\" is a unique identifier that every individual patient registered with Great Britain's National Health Service (NHS) has.\n\n[You can find out more about NHS numbers on the nhs.uk website.](https://www.nhs.uk/NHSEngland/thenhs/records/nhs-number/Pages/what-is-the-nhs-number.aspx)\n\n### How do you validate an NHS number?\n\nNot every number is a valid NHS number - they must conform to a simple algorithm to be considered valid. Before the algorithm is run, there are a few things to note about NHS numbers:\n\n- An NHS number must be numeric\n- An NHS number must be 10 digits long\n- An NHS number can begin with a `0`, so it should be handled as a string, not an integer\n- The last digit of the NHS number is used as the \"check digit\" for the algorithm\n\nThe algorithm to validate an NHS number using its \"check digit\" is as follows:\n\n1. Multiple each of the first nine digits by a defined weight, shown below:\n\n| Original digit | Multiplied by |\n| -------------- | ------------- |\n| 1              | 10            |\n| 2              | 9             |\n| 3              | 8             |\n| 4              | 7             |\n| 5              | 6             |\n| 6              | 5             |\n| 7              | 4             |\n| 8              | 3             |\n| 9              | 2             |\n\n2. Calculate the sum of all 9 multiplications\n3. Divide this sum by 11 and get the remainder\n4. Subtract 11 from the remainder to get the total\n5. If the total is 11 then the identifier, otherwise the identifier is the total\n6. If the identifier is 10, then the NHS number is wrong\n7. If the identifier is the same as the check digit, then the NHS number is correct\n\n## 💾 Installation\n\nYou can install the package with [Composer](https://getcomposer.org/) using the following command:\n\n```bash\ncomposer require imliam/php-nhs-number:^1.1\n```\n\n## 📝 Usage\n\nYou can new up the `NhsNumber` object by passing through an NHS number.\n\n``` php\n$nhsNumber = new \\ImLiam\\NhsNumber\\NhsNumber('9077844449');\n```\n\nThe NHS recommend that when displaying an NHS number to a human, it should be spaced out in a 3-3-4 format, which helps it to be easier to read. To do this, call the `-\u003eformat()` method or cast the object to a string.\n\n```php\necho $nhsNumber-\u003eformat();\n// '907 784 4449'\n\necho (string) $nhsNumber;\n// '907 784 4449'\n```\n\nTo get a boolean representation of whether or not the current number is valid, call the `-\u003eisValid()` method on the object.\n\n```php\n$nhsNumber-\u003eisValid();\n// true\n```\n\nIf you need more information on why a given NHS number may be invalid, you can call the `-\u003evalidate()` method directly. This will throw an `InvalidNhsNumberException` exception whose message will explain why the number is not valid.\n\n```php\ntry {\n    $nhsNumber = new \\ImLiam\\NhsNumber\\NhsNumber('9077844446');\n    $nhsNumber-\u003evalidate();\n} catch (\\ImLiam\\NhsNumber\\InvalidNhsNumberException $e) {\n    echo $e-\u003egetMessage();\n    // \"The NHS number's check digit does not match.\"\n}\n```\n\nTo generate a single or multiple random valid NHS numbers for testing purposes, call the `::getRandomNumber()` or `::getRandomNumbers($count)` static methods respectively.\n\n```php\necho \\ImLiam\\NhsNumber\\NhsNumber::getRandomNumber();\n// '9278462608'\n\necho \\ImLiam\\NhsNumber\\NhsNumber::getRandomNumbers(5);\n// ['7448556886', '0372104223', '8416367035']\n```\n\n## ✅ Testing\n\n``` bash\ncomposer test\n```\n\n## 🔖 Changelog\n\nPlease see [the changelog file](CHANGELOG.md) for more information on what has changed recently.\n\n## ⬆️ Upgrading\n\nPlease see the [upgrading file](UPGRADING.md) for details on upgrading from previous versions.\n\n## 🎉 Contributing\n\nPlease see the [contributing file](CONTRIBUTING.md) and [code of conduct](CODE_OF_CONDUCT.md) for details on contributing to the project.\n\n### 🔒 Security\n\nIf you discover any security related issues, please email liam@liamhammett.com instead of using the issue tracker.\n\n## 👷 Credits\n\n- [Liam Hammett](https://github.com/imliam)\n- [Peter Fisher](https://github.com/pfwd/NHSNumber-Validation) for the original class\n- [All Contributors](../../contributors)\n\n## ♻️ License\n\nThe MIT License (MIT). Please see the [license file](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimliam%2Fphp-nhs-number","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimliam%2Fphp-nhs-number","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimliam%2Fphp-nhs-number/lists"}