Australian Medicare Number Validation
Australian Medicare Number Validation
Australian Medicare card numbers consist of 11 digits structured as follows:

| Identifier 8-digits | First digit should be in the range 2-6 | 
| Checksum 1-digit | Digits are weighted (1,3,7,9,1,3,7,9) | 
| Issue Number 1-digit | Indicates how many times the card has been issued | 
| Individual Reference Number (IRN) 1-digit | The IRN appears on the left of the cardholder’s name on the medicare card and distinguishes the individuals named on the card. | 
The IRN is not always considered part of the card number, but it is essential that it be included on Medicare claim forms.
PHP Sample Code
//   ValidateMedicareNumber
//     Checks medicare card number for validity
//     using the published checksum algorithm.
//     Returns: true if the number is valid, false otherwise.
//     Note - this expects 11 digits including the IRN.  
//     To validate numbers without IRNs, change the length
//     check to 10 digits.
//
//      Source: http://www.clearwater.com.au/code
//      Author: Guy Carpenter
//     License: The author claims no rights to this code.
//              Use it as you wish.
 
function ValidateMedicareNumber($MedicareNo)
{
    $medicareNo = preg_replace("/[^\d]/", "", $MedicareNo);
 
    // Check for 11 digits
    $length = strlen($medicareNo);
    if ($length==11) {
        // Test leading digit and checksum
        if (preg_match("/^([2-6]\d{7})(\d)/", $medicareNo, $matches)) {
            $base = $matches[1];
            $checkDigit = $matches[2];
            $sum = 0;
            $weights = array(1,3,7,9,1,3,7,9);
            foreach ($weights as $position=>$weight) {
                $sum += $base[$position] * $weight;
            }
            return ($sum % 10) == intval($checkDigit);
        }
    }
    return false;
}
Reference
It can be hard to find a definitive reference to the algorithm on the Medicare site. At the time of writing it could be found in this document: http://www.medicareaustralia.gov.au/provider/vendors/files/acir-immunisation-document-formats.pdf