|
Like this code?
Show the author your appreciation.
|
|
| |
This function lets you validate serial numbers of dollar bank notes.
| <?php
/**
* Checks if the input string is a valid Dollar banknote serial number.
*
* @param string $string
* @return bool
*/
function Dollar($string)
{
$string = strtoupper(trim($string));
if (strlen($string) == 11)
{
$charset = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'V', 'U', 'W', 'X', 'Y', 'Z');
if (in_array($string[0], $charset))
{
$string = substr($string, 1);
}
else
{
return false;
}
}
if (strlen($string) == 10)
{
$charset = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L');
if (in_array($string[0], $charset))
{
$string = substr($string, 1);
}
else
{
return false;
}
if (is_numeric(substr($string, 0, 8)))
{
$string = substr($string, 8);
}
else
{
return false;
}
$charset = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', '*', 'P', 'Q', 'R', 'S', 'T', 'V', 'U', 'W', 'X', 'Y', 'Z');
if (in_array($string[0], $charset))
{
return true;
}
}
return false;
}
// Examples:
var_dump(Dollar('CB47511319A'));
?> | | |