Skip to content

gunjam/is-national-insurance-number

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status codecov.io Code Coverage XO code style

is-national-insurance-number

This module provides a function to validate UK National Insurance numbers.

It validates strings strictly (must be upper case, contain no spaces, dashes etc).

I recommend santising your input before validation.

Installing

  npm install is-national-insurance-number --save

Example usage

const isNino = require('is-national-insurance-number');

isNino('AA111111A'); // true
isNino('thrasdfag'); // false

Using provided sanitiser

const sanitiseNino = require('is-national-insurance-number/sanitise-nino');

sanitiseNino('aa 11 22 33 a'); // AA112233A
sanitiseNino('AA-11-22-33-A'); // AA112233A
sanitiseNino('aa112233A! 😺'); // AA112233A

Express like example

View

<form method="post">
  <label for="nino">National Insurance number</label>
  <input type="text" name="nino" id="nino"/>
  <button type="submit">Submit</button>
</form>

Router

app.post((req, res) => {
  const nino = sanitiseNino(req.body.nino);

  if (isNino(nino)) {
    res.redirect('/good-nino-page');
  } else {
    const errors = {nino: 'Bad nino!'};
    res.render('form', {errors});
  }
});

Pull requests welcome! 😸

About

Validates string is a UK National Insurance number

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published