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

Card number and CVC lengths #688

Open
rolinger opened this issue Mar 31, 2022 · 3 comments
Open

Card number and CVC lengths #688

rolinger opened this issue Mar 31, 2022 · 3 comments

Comments

@rolinger
Copy link

rolinger commented Mar 31, 2022

When users add a CC number it instantly shows what type of card it is....but every type of card has its own required card number lengths and CVC lengths. Most cards CVCs are 3 digits, but Amex is 4. Most card lengths are 16, but some Visa's are 13 and Amex is 15.

Is there any method in cleave.js that can return the required card number lengths and the required CVC lengths?

I am doing form validation on a variety of fields, and prior to trying to use cleave.js my inputValidator strictly checked for cardNumberLength=16 (no spaces)) and cardCVCLength=3. But cleave.js inserts spaces into the card number taking a visa from 16 characters to 19....and an AMEX (which I wasn't testing for previously) is 15 characters, but with spaces would be 17 (or 18). So now my validator is causing problems when combined with cleave.js. Thus in order for both to cleanly to work, I need to be able to pass the card type lengths to my validator.

As far as I can tell, cleave.js does not return those values.

@rolinger
Copy link
Author

For anyone interested:

    onCreditCardTypeChanged: function (type) {
      console.log(type) ;
      switch(type) {
        case 'amex' :
          ccLength = [15] ;
          cvcLength = 4 ;
          break ;
        case 'mastercard' :
          ccLength = [16] ;
          cvcLength = 3 ;
          break ;
        case 'visa' :
          ccLength = [13,16] ;
          cvcLength = 3 ;
          break ;
        case 'diners' :
          ccLength = [14,15,16,17,18,19] ;
          cvcLength = 4 ;
          break ;
        case 'discover' :
          ccLength = [16] ;
          cvcLength = 3 ;
          break ;
        case 'jcb' :
          ccLength = [16] ;
          cvcLength = 3 ;
          break ;
        case 'jcb' :
          ccLength = [16] ;
          cvcLength = 3 ;
          break ;
        case 'dankort' :
          ccLength = [16] ;
          cvcLength = 3 ;
          break ;
        case 'uatp' :
          ccLength = [15] ;
          cvcLength = 3 ;
          break ;
        case 'mir' :
          ccLength = [16,19] ;
          cvcLength = 3 ;
          break ;
        case 'unionpay' :
          ccLength = [16,17,18,19] ;
          cvcLength = 3 ;
          break ;
      }
    }

@Gjbf677
Copy link

Gjbf677 commented Jul 30, 2022

4115680149517302486

@Takyon21
Copy link

thanks

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

No branches or pull requests

3 participants