Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Credit card validation #924

Merged
merged 6 commits into from May 1, 2022

Conversation

alessmar
Copy link
Contributor

@alessmar alessmar commented Mar 25, 2022

Implemented Luhn algoritm to validate credit card string

Fixes Or Enhances

Make sure that you've checked the boxes below before you submit PR:

  • Tests exist or have been written that cover this particular change.

@go-playground/validator-maintainers

implemented Luhn algoritm to validate credit card string
@alessmar alessmar requested a review from a team as a code owner March 25, 2022 16:04
@coveralls
Copy link

coveralls commented Mar 25, 2022

Coverage Status

Coverage increased (+0.03%) to 75.201% when pulling 40d028e on alessmar:credit-card-validator into bb30072 on go-playground:master.

baked_in.go Outdated

ccDigits := strings.Split(creditCard.String(), "")
size := len(ccDigits)
if size < 14 || size > 16 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Globally, card numbers (PAN) can be 12 - 19 digits
(see https://en.wikipedia.org/wiki/Payment_card_number)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marrow16 thank you for pointing out the min and max size of a PAN. I've updated the code according to the documentation that you provided.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marrow16 @alessmar
Hi folks,
Actually PAN length is in range 10-19

IIN length has been extended to 8-digits in fifth edition of ISO/IEC 7812 published in 2017[[2]](https://en.wikipedia.org/wiki/Payment_card_number#cite_note-2) and PAN will continue to remain variable length, ranging from 10 to 19 digits.


ccDigits := strings.Split(creditCard.String(), "")
size := len(ccDigits)
if size < 12 || size > 19 {
Copy link

@grandeto grandeto Apr 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
I wrote this comment below the previous comments' thread.
However just in case putting it also here

The correct PAN validation nowadays should be size < 10 || size > 19

Here is the official statement:

https://www.iso.org/news/2016/11/Ref2146.html

Within the current version of ISO/IEC 7812-1, an IIN is defined as a fixed-length numeric of six digits. The standard also defines the Primary Account Number (PAN), a number which is used to identify an individual account holder. The PAN is of variable length, ranging from 8 to 19 digits.

Due to the increasing number of card issuers, there is expected to be a shortage in the available supply of IINs. Therefore, ISO/IEC 7812-1 is being revised to expand the IIN to an eight-digit numeric value from the current six digits. The PAN will continue to remain a variable length, ranging from 10 to 19 digits.

Copy link
Contributor

@deankarn deankarn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@deankarn deankarn merged commit dd2857a into go-playground:master May 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants