validatorjs / validator.js

String validation
MIT License
23.12k stars 2.31k forks source link

Some valid payment card numbers are not accepted #1559

Open dspinellis opened 3 years ago

dspinellis commented 3 years ago

The performed check is overly stringent (and sometimes wrong) regarding the accepted formats. The following illustrates two cases derived from this site.

> const validator = require('validator');
> validator.isCreditCard('4716967026053481241') // OK; Visa
true
> validator.isCreditCard('6396827370876380') // Not OK; Maestro
false
> validator.isCreditCard('5020198842623966') // No OK; InstaPayment
false

More details on number formats are available here, here, and here. I think the correct validation approach would be to check the length of known issuer identification numbers (IINs) and for the rest, accept numbers with 12–19 digits that have a valid Luhn checksum. I'll try to provide a fix, and would welcome any comments regarding this approach.

profnandaa commented 3 years ago

PR welcome!

metajunaid commented 3 years ago

Please review the PR, I have added validations for Maestro and Insta Payments Card https://github.com/validatorjs/validator.js/pull/1701