Hi,
this is a very specific question. If it is too specific for this forum, please feel free to tell me so.
I added a Contact Form 7 formular on the following site:
http://www.waschhalle-tuttlingen.de/kundenkarte-laden/
You see a field called “Kartennummer” where you should type a EAN-13 barcode. I would like to validate this barcode with its checksum. I know the code how to do the checking and I know that this probably would work with a WP-Filter. But I have no idea how to add such a filter and where.
Can anyone help? Probably just with a link to a tutorial.
Regards
Georg
function validate_EAN13Barcode($barcode)
{
if (!preg_match("/^[0-9]{13}$/", $barcode)) {
return false;
}
$digits = $barcode;
$even_sum = $digits[1] + $digits[3] + $digits[5] +
$digits[7] + $digits[9] + $digits[11];
$even_sum_three = $even_sum * 3;
$odd_sum = $digits[0] + $digits[2] + $digits[4] +
$digits[6] + $digits[8] + $digits[10];
$total_sum = $even_sum_three + $odd_sum;
$next_ten = (ceil($total_sum / 10)) * 10;
$check_digit = $next_ten - $total_sum;
if ($check_digit == $digits[12]) {
return true;
}
return false;
}