JavaScript NHS Number Validator

A simple JS NHS number validator for Node and browsers

This project is maintained by spikeheap

nhs-number-validator

Build Status

A simple NHS number validator, following the process described in the NHS Data Dictionary.

Installation

NPM
npm install --save nhs-number-validator
Bower
bower install --save nhs-number-validator

Usage

Command line / terminal

To run the interactive validation tool, install the NPM module globally:

npm install -g nhs-number-validator

and nhs-number-validator will be added to your path:

$ nhs-number-validator
Enter NHS numbers to validate, Ctrl-D to exit
> 123
*INVALID
> 2983396339
 VALID

You can also install the tool for a single project, and just reference the executable in your project:

npm install nhs-number-validator
./node_modules/.bin/nhs-number-validator
# or
`npm bin`/nhs-number-validator
Node/Browserify

For environments supporting require/exports:

var validator = require('nhs-number-validator');

validator.validate('2983396339') // => true
validator.validate('test') // => false
Browsers

Any environment which exposes window will have the nhsNumberValidator variable attached when index.js is loaded, e.g.:

<script src="./bower_components/nhs-number-validator/index.js"></script>
<script>
  var validator = window.nhsNumberValidator
  validator.validate('2983396339') // => true
  validator.validate('test') // => false

  // or just use it directly if you prefer:
  window.nhsNumberValidator.validate('2983396339') // => true

  // you don't even need `window`:
  nhsNumberValidator.validate('2983396339') // => true
</script>

Try it out

Authors and Contributors

Support or Contact

If you have any problems or suggestions, please create an issue, and we'll give you a hand. Pull Requests are very welcome too!