Meteor.methods({
    checkHKID: function (hkid) {
        var hkidPat = /^([A-Z]{1,2})([0-9]{6})([A0-9])$/;
        var matchArray = hkid.match(hkidPat);
        if(matchArray == null){throw new Meteor.Error('invalid', 'The HKID entered is invalid')} else {
            var checkSum = 0;
            var charPart = matchArray[1];
            var numPart = matchArray[2];
            var checkDigit = matchArray[3];
            if (charPart.length == 2) {
                checkSum += 9 * (charPart.charAt(0).charCodeAt(0) - 55);
                checkSum += 8 * (charPart.charAt(1).charCodeAt(0) - 55);
            } else {
                checkSum += 8 * (charPart.charCodeAt(0)-55);
                checkSum += 324;
            }
            for (var i = 0, j = 7; i < numPart.length; i++, j--){
                checkSum += j * numPart.charAt(i);
            }

            var remaining = checkSum % 11;
            var checkNumber = 11 - remaining;
            if(checkDigit == checkNumber) {} else {throw new Meteor.Error('invalid', 'The HKID entered is invalid')}
        return(hkid)
    }}

});
@@ -100,16 +100,92 @@
 0-9%5D)$/;
+ // HKID format = 1 or 2 letters followed by 6 numbers and 1 checksum digit.
 %0A       
@@ -258,85 +258,19 @@
 ll)%7B
-throw new Meteor.Error('invalid', 'The HKID entered is invalid')%7D else %7B%0A    
+idError()%7D%0A
     
@@ -295,28 +295,24 @@
  0;%0A        
-    
 var charPart
@@ -333,28 +333,24 @@
 1%5D;%0A        
-    
 var numPart 
@@ -366,36 +366,32 @@
 ray%5B2%5D;%0A        
- 
-   
 var checkDigit =
@@ -414,20 +414,16 @@
         
-    
 if (char
@@ -446,36 +446,32 @@
 ) %7B%0A            
-  
-  
 checkSum += 9 * 
@@ -503,36 +503,32 @@
 odeAt(0) - 55);%0A
-    
             chec
@@ -593,16 +593,28 @@
        %7D
+%0A           
  else %7B%0A
@@ -711,38 +711,38 @@
 24;%0A            
-%7D%0A
     
+%7D%0A
         for (var
@@ -852,27 +852,24 @@
       %7D%0A
-%0A  
         
   var re
@@ -856,26 +856,24 @@
   %7D%0A        
-  
 var remainin
@@ -891,20 +891,16 @@
 m %25 11;%0A
-    
         
@@ -941,20 +941,16 @@
         
-   
- 
 if(check
@@ -976,16 +976,67 @@
 r) %7B
-%7D else %7B
+return(%22valid%22)%7D%0A        function idError () %7B%0A            
 thro
@@ -1095,17 +1095,16 @@
 nvalid')
-%7D
 %0A       
@@ -1108,27 +1108,16 @@
     
-return(hkid)
+%7D%0A
 %0A    %7D
-%7D
 %0A%0A%7D)

Clean up HKID verification code