Hi, i've got a bit of code that already validates some card numbers, from visa, MC, and a few others. Now, i need to include support for UK Switch, but they have many bin numbers that vary from 16 to 19 digits long.
Below, is what i typically use for MasterCard:
class cc_validation {
var $cc_type, $cc_number, $cc_expiry_month, $cc_expiry_year;
function validate($number, $expiry_m, $expiry_y) {
$this->cc_number = ereg_replace('[^0-9]', '', $number);
if (ereg('^5[1-5][0-9]{14}$', $this->cc_number) and CC_ENABLED_MC=='1') {
$this->cc_type = 'Master Card';
and here is what i have come up for a few bin's for UK Switch:
} elseif (ereg(^(675938|675939|675940)([0-9]{10})([0-9]{2})([0-9])?$', $this->cc_number) and CC_ENABLED_UKSWITCH=='1') {
$this->cc_type = 'UK Switch';
Am i doing this correctly, so that any of the above BIN's for UK switch can be 16, 18, or 19 digits long ?
Thanks.. 🙂