validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

isCreaditCard must be world class not just Popular ones

Open mhf-ir opened this issue 3 years ago • 6 comments

For example 5022291047705718 is for https://en.wikipedia.org/wiki/Bank_Pasargad. What about another countries?

https://github.com/persian-tools/persian-tools#bank-number-validation-and-get-the-name-of-the-bank-by-bank-account-number

  • All banks has special luhn algorithm with special prefix.
  • All banks that has wikipedia page is important for users, so must be implemented.
  • Banks must has unique name that wikipedia title page is good for that.

Such as many validator this required list of valid banks names such as :

  • https://en.wikipedia.org/wiki/American_Express
  • https://en.wikipedia.org/wiki/Bank_Pasargad
const list = {
    'american_express': (str) => {},
    'bank_pasargad': (str) => {},
};

isCreditCard("american_express_LUHN") // american_express
isCreditCard("bank_pasargad_LUHN") // bank_pasargad

mhf-ir avatar Feb 10 '21 10:02 mhf-ir

for validate isCreaditCard seem refactor required. There many bank credit cards around the world that good validator.js cover importat ones.

Witch one must be implemented?

  • How to find out it's important? I think if each bank has English Wikiepdia would be point for Popular banks. simple-icons approach
  • Many banks are world class many of them depend on countries. so country could/must part of validation.

This implementation is hard code for several banking but in many libraries use combine Luhn algorithm(that's general algorithm of validation numbers) and prefix and regexes.

https://github.com/braintree/card-validator https://github.com/braintree/credit-card-type

bank names could be wikipedia title kebab_case like american-express for American Express

mhf-ir avatar Mar 17 '21 12:03 mhf-ir

It this addressed by the PR yet? #1595

profnandaa avatar Apr 18 '21 16:04 profnandaa

@profnandaa Nope, reference must be delete. need to be discuss. What's you idea about this problem.

isLuhn required as base dependency. Need added country/brand based prefix/suffix for Luhn algorithm for each credit card.

Let's talk about implementation and change interface.

// Luhn algorithm verfication for specifiec Luhn not public ones. For example site: supercach.net will rise new card they will print it and give it to their customer.
isLuhn("1131537811") // true

// for special not public one
// could accept like https://github.com/braintree/credit-card-type/blob/master/src/lib/card-types.ts
isLuhn("1131537811", {
  lengths: [10],
});

// 5022291047705718 specific for `IR` and `bank_pasargad`
// 375556917985515 for `american_express` and it's serve some countires: https://merchantmachine.co.uk/visa-mastercard-amex/

// generaly is true
isCreditCard("5022291047705718"); // true
isCreditCard("375556917985515"); // true

// it's in Iran
isCreditCard("5022291047705718", {
 region: ["IR", "DE"],
}); // true

// amercian express support 
isCreditCard("375556917985515", {
 region: ["IR", "IT"],
}); // true

// amercian express not supported in Iran
isCreditCard("5022291047705718", {
 region: ["IR"],
}); // true

// it's bank_pasargad
isCreditCard("5022291047705718", {
 types: ["bank_pasargad", "mastercard"],
}); // true

// it's in Iran and bank_pasargad
isCreditCard("5022291047705718", {
 region: ["IR"],
 types: ["bank_pasargad"],
}); // true


// It's not supported in Iran so types not checked
isCreditCard("375556917985515", {
 region: ["IR"],
 types: ["bank_pasargad", "american_express"],
}); // false

mhf-ir avatar Apr 18 '21 17:04 mhf-ir

I have a closer look at for the next release (after this month) then. Please send in your proposal.

profnandaa avatar Apr 18 '21 17:04 profnandaa

interface would be something like this:

interface LuhnOptions {
  patterns: number[] | [number[]];
  gaps: number[];
  lengths: number[];
}
type isLuhn = (str: string, options: LuhnOptions) => boolean;


interface CreditCardOptions {
  region: string[],
  types: string[],
}
type isCreditCard = (str: string, options: CreditCardOptions) => boolean;

If telling me how to implement i will rise PR for this issue

mhf-ir avatar Apr 18 '21 17:04 mhf-ir

@profnandaa any update on this?

mhf-ir avatar Jan 25 '22 15:01 mhf-ir