|
|
|
|
Like this code?
Show the author your appreciation.
|
| |
This function lets you validate serial numbers of Euro bank notes.
| <?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;
}
// Example:
var_dump(Euro('X01587275921'));
?> | | |