Pages

Monday, August 31, 2015

The Function of the "Check Digit" in the Individual Number System

There, it will come one more month later...

The Individual Number system will start also here in Japan. (2015-10-05) In this blog as well, I have exemplified several Workflows (Business Process) about "Process of Individual Number collection".

And I am going to introduce examples of utilizing "Corporation Number" also in the following weeks. Also,I am planning to publish utilization examples of "Web-API function" of Corporate Number system sequentially as soon as I confirm operation on "Pre-verification environment".

In this article, I will summarize on "Error detection" which is indispensable in the business that deal with "Individual Number".

The Workflow definition below is a sample which allows you to experience 'accuracy check' on input data. It is set both of [1] the mechanism of automatic data checking during input (JavaScript in input screen), and [2] the mechanism of data checking on the server computer (JavaScript in Script Step)

By the way, "Check Digit" means a character for inspection. It is used widely for such as "Credit card number", "Product code"(EAN / JAN barcode), "International Standard Book Number" (ISBN), etc. In the case of "Individual Number" in Japan,
  • Corporation Number (13 digits): The leftmost digit
  • Individual Number (12 digits): The rightmost digit
are calculated by the "specific formula", and is added.

[Check Digit sample:"Test form" screen]


[Check Digit sample]

In this example, the input value is checked in real time in the "data input screen", first. (Corporate No.: 1, and Individual No.: 1)

That is, the moment that the "corporation number (13 digits)" and "personal number (12 digits)" is entered, the system calculates the "number for inspection" by the process of the browser side (JavaScript processing), and the verification of the inspection character is carried out. Simple typo will be detected at that moment.

Furthermore, checking in the "Script Step" is set also. (Corporate No.: 2, and Individual No.: 2)

This is useful for cases that to be examined / validation server side again, like when receiving a Corporation Number from another system. Of course, although it could be a "useless calculations" if it has already inspected on the other system side, it is not a big problem as it is a small amount of calculation. (It may be combined with the "Input Screen check".)

In either case, it is a mechanism that can detect the "error data" automatically.

You can feel it if you try to experience input actually, to make "erroneous input" is extremely difficult. Although more than two mistakes in 13-digit / 12-digit number is needed, all of the erroneous input (input error) will be detected. We would like to incorporate this to the Workflow in which the administrative procedure documents are created, actively. You will be able eliminate the time and effort such as "re-apply" or "response to call". Consequently, it also leads to a reduction in the administrative costs.


== Corporation Number check
* "Corporation Number" is composed of 13 digits. First character (leftmost) is the check digit.

= Script setting on the input screen (Corporation Number)
<script type="text/javascript"> 
jQuery('input[name="data[1].input"]').on('keydown keyup keypress change',function(){ 
//If there is an alteration in Text form value of Data Item number "1", 

var thisValueLength = jQuery(this).val().length; 

//Calculate Check Digit if the number of characters is 13 digits 
if( thisValueLength == 13 ){ 
var mysum = 0; 
var thisValue = jQuery(this).val(); 

// for( i=1; i<13; i++){ 
// mysum += parseInt( thisValue.charAt(i) ) * (i % 2 + 1); 
// } 

mysum += parseInt( thisValue.charAt(1) ) * 2; 
mysum += parseInt( thisValue.charAt(2) ); 
mysum += parseInt( thisValue.charAt(3) ) * 2; 
mysum += parseInt( thisValue.charAt(4) ); 
mysum += parseInt( thisValue.charAt(5) ) * 2; 
mysum += parseInt( thisValue.charAt(6) ); 
mysum += parseInt( thisValue.charAt(7) ) * 2; 
mysum += parseInt( thisValue.charAt(8) ); 
mysum += parseInt( thisValue.charAt(9) ) * 2; 
mysum += parseInt( thisValue.charAt(10) ); 
mysum += parseInt( thisValue.charAt(11) ) * 2; 
mysum += parseInt( thisValue.charAt(12) ); 

var checkdigitnum = 9 - mysum % 9; 
var typedcd = parseInt( thisValue.charAt(0) ); 

//Rewrite the HTML of #mymessage1 
if( typedcd == checkdigitnum ){ 
jQuery( '#mymessage1' ).html("OK"); 
} else { 
jQuery( '#mymessage1' ).html("<font color=red>NG</font>"); 
} 
} else { 
jQuery( '#mymessage1' ).html("<font color=blue>Enter 13 digits number</font>"); 
} 

}); 
</script> 

= Script inspection on automatic Step (Corporation Number)
//// == Retrieving == 
var mynumber = data.get("3") + "";  

//// == Calculating == 
if( mynumber == "null" ){ 
  retVal.put("4", "(null)" ); 
}else if( mynumber.length == 13 ){ 
  var mysum = 0; 

  for( i=1; i<13; i++){ 
    mysum += parseInt( mynumber.charAt(i) ) * (i % 2 + 1); 
  } 

  var checkdigitnum = 9 - mysum % 9; 
  var typedcd = parseInt( mynumber.charAt(0) ); 

//// == Updating == 
  if( typedcd == checkdigitnum ){ 
    retVal.put("4", "OK" );  
  } else { 
    retVal.put("4", "Check-Digit ERROR" );  
  } 

} else { 
  retVal.put("4", "Number of digits ERROR" );  
} 

== Individual Number check
* "Individual Number" is composed of 12 digits. Last character (rightmost) is the check digit.

= Script setting on the input screen (Individual Number)
<script type="text/javascript"> 
jQuery('input[name="data[7].input"]').on('keydown keyup keypress change',function(){ 
//If there is an alteration in Text form value of Data Item number "7" 

var thisValueLength = jQuery(this).val().length; 

//Calculate Check Digit if the number of characters is 12 digits 
if( thisValueLength == 12 ){ 
  var mysum = 0; 
  var thisValue = jQuery(this).val(); 

  for( i=0; i<5; i++){ 
    mysum += (11 - i - 5) * parseInt( thisValue.charAt(i) ); 
  } 
  for( i=5; i<11; i++){ 
    mysum += (11 - i + 1) * parseInt( thisValue.charAt(i) ); 
  } 
  var checkdigitnum = 11 - mysum % 11; 
  if( checkdigitnum > 9 ){ checkdigitnum = 0; } 

  var typedcd = parseInt( thisValue.charAt(11) ); 

  //Rewrite the HTML of #mymessage7 
  if( typedcd == checkdigitnum ){ 
    jQuery( '#mymessage7' ).html("OK"); 
  } else { 
    jQuery( '#mymessage7' ).html("<font color=red>NG</font>"); 
  } 
} else { 
  jQuery( '#mymessage7' ).html("<font color=blue>Enter 12 digits number</font>"); 
} 
}); 
</script> 

= Script inspection on automatic Step (Individual Number)
//// == Retrieving == 
var mynumber = data.get("8") + ""; 

//// == Calculating == 
if( mynumber == "null" ){ 
  retVal.put("9", "(null)" ); 
}else if( mynumber.length == 12 ){ 
  var mysum = 0; 

  for( i=0; i<5; i++){ 
    mysum += parseInt( mynumber.charAt(i) ) * (11 - i - 5); 
  } 
  for( i=5; i<11; i++){ 
    mysum += parseInt( mynumber.charAt(i) ) * (11 - i + 1); 
  } 
  var checkdigitnum = 11 - mysum % 11; 
  if( checkdigitnum > 9 ){ checkdigitnum = 0; } 

  var typedcd = parseInt( mynumber.charAt(11) ); 

//// == 代入 / Updating == 
  if( typedcd == checkdigitnum ){ 
    retVal.put("9", "OK" );  
  } else { 
    retVal.put("9", "Check-Digit ERROR" );  
  } 

} else { 
  retVal.put("9", "Number of digits ERROR" );  
} 

[Data Items list]


[Free Download]
<Similar Models>
<<Related Articles>>

[Japanese Entry (和文記事)]