# Posted By

j_junyent on 01/13/08

# Statistics

Viewed 178 times
Favorited by 0 user(s)

# Euro banknote validation

/ Published in: PHP
Save to your folder(s)

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.

Copy this code and paste it in your HTML
`<?php /** * Checks if the input string is a valid Euro note serial number. * * @param string \$string * @return bool */function Euro(\$string){	settype(\$string, 'string'); 	if (strlen(\$string) != 12)	{		return false;	} 	\$string = str_replace(array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'), array(2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9), strtoupper(\$string)); 	\$stack = 0; 	for (\$i = 0; \$i < 12; \$i++)	{		\$stack += \$string[\$i];	} 	if (\$stack % 9 == 0)	{		return true;	} 	return false;} ?>`

## Comments

Subscribe to comments

You need to login to post a comment.