CancelImage Upload

Validating New Zealand's National Health Index Number using Regular Expressions

New Zealand's National Health Index Number primarily servers the puropse of providing a unique ID Code for individuals within the country's health system. Format wise it consists of 7 characters, the first 3 being alphanumeric, while the last 4 are numbers. The 4th of these numbers is a check digit, while the first 6 characters do not have any relevance to the individual they belong to (Name, areacode, etc...). Here then is the format:

ABC4567

Based on this format we can dvise the following regular expression syntax:

^([a-zA-Z]){3}([0-9]){4}?$

And here a JavaScript example of this code in action:

<html>
<head>
<title>New Zealand's National Health Index Number Validation with JavaScript</title>

<script language="JavaScript">

function nhi_validate(nhi)
{

var regnhi = /^([a-zA-Z]){3}([0-9]){4}?$/;

if(regnhi.test(nhi) == false)
{

document.getElementById("status").innerHTML = "National Health Index Number is not yet valid.";

}
else
{

document.getElementById("status").innerHTML = "You have entered a valid National Health Index!";

}
}

</script>

<style type="text/css">
<!--
body {
background:#CCCCFF;
}

div {
width: 100%;
text-align: center;
margin-top:150px;
}

span {
color: #000099;
font: 8pt verdana;
font-weight:bold;
text-decoration:none;
}

input {
color: #000000;
background: #F8F8F8;
border: 1px solid #353535;
width:250px;
font: 8pt verdana;
font-weight:normal;
text-decoration:none;
margin-top:5px;
}
-->
</style>
</head>
<body>

<div>
<span id="status">Please enter a valid National Health Index Number.</span><br>
<input type="text" name="nhi" onkeyup="nhi_validate(this.value);">
</div>

</body>
</html>


Login
Want to leave a comment?

No problem. Just enter your email and password below.


register | home | reminder

myDesignTool Networking • www.mydesigntool.cominfo@mydesigntool.com