Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checksum...Euro notes checksum Validation Problem!

Status
Not open for further replies.

Theml

Programmer
Apr 16, 2011
1
IE
Hello,
I 'm working on Euro banknote validation, where I'm using authentication of the serial number of Euro banknotes by the calculation of the "checksum". Basically what this algorithm does is to replace the first letter of the serial number by a number (each letter represents where the banknote is originally from), then it calculates the sum of all digits. If the remaining of the division of that sum by 9 is 0 then your note is valid.

More info:
Some test data
EURO Serial Number
V44671133335
T27620110932
A00000000007

The last serial number "A00000000007" works properly. but the first two for some reason don't work properly.

Those are my javascript codes:
Code:
<html>
<body>
<script type="text/javascript">
		
var EBNSArray = new Array ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90");

function validation() 
{ 
    var i; 
	var EBNS = document.forms["ebnsform"]["EBNS"].value; 

	if (EBNS.length != 11 && EBNS.length != 12)
	{
	     alert ("Incorrect EBNS, please enter the correct EBNS"); 
	     return false; 
	}

	if (EBNS.length == 11)
	{
		var letter_real = EBNS.charAt(0); 
	}	
	
	if (EBNS.length == 12)
	{
		var letter_real = EBNS.charAt(1); 
	}	
	
    var letter_enter = EBNS.substring(1,11); 
    
	var checkLetter = letter_enter % 9
	
    if (letter_real == EBNSArray[checkLetter]) 
    {  
	alert ("Correct EBNS");
        return true; 		 
    } 
    else 
    { 
	alert ("Incorrect EBNS, please enter the correct EBNS");			
        return false; 
    }          
} 
</script>
<form id="ebnsform">
<p>Euro Banknote Number: <input type="text" id="EBNS" /><br /></form></center>
<input type="button" onclick="validation()" value="Validation"/></p>
</body>
</html>
 
Hi

You should use the [tt]charCodeAt()[/tt] method instead of [tt]charAt()[/tt] to no complicate it. That checksum expression should be simple as :
Code:
(EBNS.charCodeAt(0)+EBNS.substr(1))%9==0
( Note that I not found any reference saying that the letter can be the second character. You may have to add that condition. )


Feherke.
 
This:

[ode]
var checkLetter = letter_enter [red]%[/red] 9
[/code]

Is not a valid division. If you really want to divide by 9 use /.

Code:
 var checkLetter = letter_enter [red]/[/red] 9

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Duh!. goes to show you why I should not answer questions in the morning on a saturday.

Sorry about that. Yes % is valid. then ignore the last post.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top