Search code examples
javascriptvalidationnumbers

How do I validate an Australian Medicare number?


I'm developing an online form in which user-entered Medicare numbers will need to be validated.

(My specific problem concerns Australian Medicare numbers, but I'm happy for answers regarding American ones too. This question is about Medicare numbers in general.)

So how should I do it?

(It would be good to have the answer in Javascript or a regex.)


Solution

  • The regex supplied by Jeffrey Kemp (March 11) would help to validate the allowed characters, but the check algorithm below should be enough to validate that the number conforms to Medicare's rules.

    The Medicare card number comprises:

    • Eight digits;
    • A check digit (one digit); and
    • An issue number (one digit).

    Note: the first digit of the Medicare card number should be in the range 2 to 6.

    Medicare card number check digit calculation

    1. Calculate the sum of: ((digit 1) + (digit 2 * 3) + (digit 3 * 7) + (digit 4 * 9) + (digit 5) + (digit 6 * 3) + (digit 7 * 7) + (digit 8 * 9))

    where digit 1 is the highest place value digit of the Medicare card number and digit 8 is the lowest place value digit of the Medicare card number.

    Example: for Medicare card number '2123 45670 1', digit 1 is 2 and digit 8 is 7.

    1. Divide the calculated sum by 10.
    2. The check digit is the remainder.

    Example: For Medicare card number 2123 4567.

    1. (2) + (1 * 3) + (2 * 7) + (3 * 9) + (4) + (5 * 3) + (6 * 7) + (7 * 9) = 170
    2. Divide 170 by 10. The remainder is 0.
    3. The check digit for this Medicare number is 0.

    Source: "Use of Healthcare Identifiers in Health Software Systems - Software Conformance Requirements, Version 1.4", NEHTA, 3/05/2011