Javascript UK National Insurance Number Validation

This JavaScript function check the format validity of a UK National Insurance Number specified by the supplied parameter. Note that it does not check that the number given is an allocated UK National Insurance Number.

The definition of a valid National Insurance Number has been taken from the official specification. Lowercase characters are permitted, but are converted to uppercase on return.

If the parameter is in the correct format for a National Insurance Number, the function returns the National Insurance Number converted to uppercase. Otherwise it returns a value of false.

Try the JavaScript routine: Enter National Insurance Number:

In this example, the input field has an id of nino, and the button has an onclick="testNINO();" associated with it. This latter function calls the main checkNINO function as follows:
function testNINO () {
  var myNINO = document.getElementById('nino').value;
  if (checkNINO (myNINO)) {
    document.getElementById('nino').value = checkNINO (myNINO);
    alert ("National Insurance Number has a valid format");
  } 
  else alert ("National Insurance Number has invalid format");
}   

Download compressed JavaScript file (781 bytes)