Validate credit card

Validates card number using Luhn algorithm. Read more.

php
fork add to bundle source
function credit_card_validate($number) { $number=preg_replace('/\D/', '', $number); $number_length=strlen($number); $parity=$number_length % 2; $total=0; for ($i=0; $i<$number_length; $i++) { $digit=$number[$i]; if ($i % 2 == $parity) { $digit*=2; if ($digit > 9) { $digit-=9; } } $total+=$digit; } return ($total % 10 == 0) ? TRUE : FALSE; }

usage

load_function('credit_card_validate'); echo credit_card_validate('1111-2222-3333-4444'); // 1
← how to use this in app?
create log ...inout