Function Repository Resource:

ValidPANQ

Source Notebook

Verify a credit or debit card's payment account number

Contributed by: Dave Middleton

ResourceFunction["ValidPANQ"][int]

returns True when int is a valid Payment Account Number (PAN).

Details

The Payment Account Number (PAN) is the card identifier found on payment cards such as debit and credit cards, but also i.e. on stored-value cards and gift cards. The PAN is typically embossed or printed on the front of a payment card. It is also encoded on the magnetic stripe and card's (EMV) chip.
A Payment Account Number length ranges from 12 to 19 Integer digits, depending on the card issuer and type of card.
This ResourceFunction is a demonstration of the Luhn algorithm for decimal number error detection. The Luhn algortihm is used in online payment forms to verify the validity of a payment card.
ValidPANQ verifies whether the PAN is valid (ISO/IEC 7812).
ValidPANQ threads over lists.
ResourceFunction["ValidPANQ"] cannot be used to identify which financial institution or organization issued the card. An Issuer Identification Number (IIN) is the first six or eight digits of a Payment Account Number.
All Payment Account Numbers in the examples in this documentation are entirely fictitious. Any similarity to actual Payment Account Numbers is purely coincidental.

Examples

Basic Examples (1) 

Verify whether this 16-digits Visa Payment Account Number is valid:

In[1]:=
ResourceFunction["ValidPANQ"][4751306171192168]
Out[1]=

Scope (1) 

ValidPANQ has the Listable attribute, so one can check whether the MasterCard and AMEX Payment Account Numbers with a length 16 and 15 digits, respectively are valid:

In[2]:=
ResourceFunction["ValidPANQ"]@{5220787701618360, 375340009670498}
Out[2]=

Properties and Relations (1) 

About 10% of possible values are valid:

In[3]:=
Counts@ResourceFunction["ValidPANQ"]@
  RandomInteger[{10^15, 10^17}, 1000]
Out[3]=

Neat Examples (1) 

The Luhn algorithm is used in many Identity Numbers, such as the International Mobile Equipment Identity (IMEI) numbers. In this case, the Luhn algorithm works in reverse. Therefore, we have to reverse the IMEI number without the last digit (which functions as a check-digit). We can verify the validity of an IMEI number with ValidPANQ:

In[4]:=
ResourceFunction["ValidPANQ"]@
 Function[a, FromDigits[{FromDigits@Reverse@Most@#, Last@#} &@IntegerDigits@a]]@
  490154203237518
Out[4]=

Publisher

Dave Middleton

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.0.0 – 22 August 2025

Related Resources

Author Notes

This ResourceFunction only tests the validity of a Payment Account Number. It does not test whether the Payment Account Number actually exists.

License Information