For those familiar with Health Card validation specification, you know that each valid health card number must pass the MOD 10 check digit process, as do credit cards and SIN numbers etc. It’s not a totally random number as you maybe once thought!

To reduce the number of rejected claims, it is recommended that the health card number is verified by the MOD 10 Check Digit.

### What is Modulus 10 / Luhn algorithm?

The **Luhn algorithm** or **Luhn formula**, also known as the “modulus 10″ or “mod 10” algorithm, named after its creator, IBM scientist Hans Peter Luhn, is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers in the United States, Canadian social insurance numbers, Israeli ID numbers, South African ID numbers, Swedish national identification numbers, Swedish Corporate Identity Numbers (OrgNr), Greek Social Security Numbers (ΑΜΚΑ), SIM card numbers, European patent application number and survey codes appearing on McDonald’s, Taco Bell, and Tractor Supply Co. receipts. It is described in U.S. Patent No. 2,950,048, granted on August 23, 1960.^{[1]}

The algorithm is in the public domain and is in wide use today. It is specified in ISO/IEC 7812-1.^{[2]} It is not intended to be a cryptographically secure hash function; it was designed to protect against accidental errors, not malicious attacks. Most credit cards and many government identification numbers use the algorithm as a simple method of distinguishing valid numbers from mistyped or otherwise incorrect numbers.

In other words…

The mod10 check algorithm is a check digit validation method that is commonly used to validate identification numbers such as credit card numbers, health card numbers and others. It first gets the last digit of the number, which is the check digit. Then it removes the check digit from the number and performs a calculation on the remaining digits, multiplying them by weights and adding the results. It then calculates the modulus of the sum, and the difference between 10 and the modulus is the expected check digit. It then compares the check digit to the expected check digit, if they are not equal then the number failed validation.

### MOD 10 for Health Cards

Example on how MOD 10 is used in Health Card validation from the Ontario MOH Technical Specifications for HCV manual:

One wonders how to implement MOD 10 check functionality in a webpage / Javascript etc.

If you don’t have real-time Health Card Validation integration in your EMR, you should use the MOD 10 check to validate health card numbers of your patients.

If you have Health Card Validation in your EMR, then you can validate individual patients’ provincial health coverage in real time against the province’s (Ontario or BC) records. The full HCV will return the validity of the health card and its version code (i.e. valid, cancelled, expired, voided, etc.), as well as patient details such as name+gender+DOB. It is difficult to get full HCV integrated into an EMR so there are many providers who don’t have access to this real time enhanced validation.

Which is why the question commonly comes up – how can I at least check if the number of the health card is correct? You can use the MOD 10 check to do that. Other uses include if you collect health card number via a web form, eForm, report template, or list, you can run a MOD 10 check function against the input to tell if the number is correct.

Here is a Mod 10 algorithm calculator online which you can use for mathematical testing purposes (don’t give it any real health card numbers!): Mod 10 algorithm Calculator (mymathtables.com)

The number “5555555555” (10 5’s) passes the MOD 10 check. Needless to say, you can’t only rely 100% on the MOD 10 check to ensure health card validity because fake numbers as above can pass the check. Credit card number generators online for testing purposes also generate MOD 10 numbers and the numbers generated aren’t real credit cards.

Here’s a Javascript function that returns true if the number it takes as input passes MOD 10.

```
// mod10 check
function mod10Check(value) {
let sum = 0;
let parity = value.length % 2;
for (let i = 0; i < value.length; i++) {
let digit = parseInt(value.charAt(i));
if (i % 2 == parity) {
digit *= 2;
if (digit > 9) {
digit -= 9;
}
}
sum += digit;
}
return (sum % 10 == 0);
}
```

To use the function, simply call it like this example which could be used in an HTML form that collects HIN:

```
// If variable "hinInputValue" (this could be your input field which you can set variable: var hinInputValue = document.getElementById(''); is 10 digits long) is 10 numbers long and mod10Check returns true for this number, it's successful. Otherwise failure.
if (/^\d{10}$/.test(hinInputValue) && mod10Check(hinInputValue)) {
// action for successful MOD 10 check goes here
}
else {
// input failed MOD 10 check; ask to re-enter correct HIN
}
```

Adjust as necessary.