NINo Stars

asterixSo the challenge today was how to make it easier for customers to get their initial password correct.
This would be based on their National Insurance number – but in lowercase, with duplicate consecutive characters replaced by an asterisk…

My idea to make this easier was to simply put some online page containing advice on how to log on initially, with a tool for easily applying the rules to a customers national insurance number.

Apparently this is complicated – needs a developer and has to be impact assessed….

Or I could just do it myself – or so I thought.

Anyway after a few minutes jogging my memory on Javascript I came up with this.

<!DOCTYPE html>

<p>Click the button to convert the string to lowercase letters.</p>
<textarea id="NINo" cols="50" name="p" rows="4">National Insurance Number</textarea>
<button onclick="myFunction()">Generate</button>

<p id="demo"></p>

function myFunction() {
   var str = document.getElementById("NINo").value;
   var res = str.toLocaleLowerCase();
   var res = res.replace(/11/g,"1*");
   var res = res.replace(/22/g,"2*");
   var res = res.replace(/33/g,"3*");
   var res = res.replace(/44/g,"4*");
   var res = res.replace(/55/g,"5*");
   var res = res.replace(/66/g,"6*");
   var res = res.replace(/77/g,"7*");
   var res = res.replace(/88/g,"8*");
   var res = res.replace(/99/g,"9*");
   var res = res.replace(/00/g,"0*");

   document.getElementById("demo").innerHTML = res;


Clunky, and I’m sure there’s a Regex version that would be tidier – but that’s for another time.


Leave a Reply