Issues

ZF-12137: CreditCard Validation / Ignore Checksum

Description

I found myself needing to check the type of a credit card number returned from my bank. Unfortunately, the bank only returns a portion of the number, say, 552122..123 to my script. I thought of using Zend Validation as it checks the starting digits in its validation check, but realised it had issues because of the checksum check. I cut the ..123 out of the number and replaced it with the appropriate number of 0's to make that cards length.

I'm basically just proposing the ability to optionally exclude the checksum check to enable Zend_Validate_CreditCard to be used to sniff the credit cards type based on the starting digits. I realise this would create security issues if it was used to validate the number, but it would be true by default, and would add another purpose to this validator.

All it requires is a few lines:

... _construct ...

    if(array_key_exists('checksum', $options)) {
        $this->_validateChecksum = $options['checksum'];
    }

... isValid...

    if($this->_validateChecksum === true) {
        if ((10 - $sum % 10) % 10 != $value[$length - 1]) {
            $this->_error(self::CHECKSUM, $value);
            return false;
        }
    }

Comments

No comments to display