Reg-Ex for JCB Credit Card Validation

前端 未结 1 923
轮回少年
轮回少年 2021-01-29 02:34

I need a reg-ex for JCB card validation with this rule, (Reference for JCB format)

First four digits must be 3088, 3096, 3112, 3158, 3337, or the first

相关标签:
1条回答
  • 2021-01-29 03:22

    Given the rules I would use this regex:

    ^(3(?:088|096|112|158|337|5(?:2[89]|[3-8][0-9]))\d{12})$

    Breakdown:

    • ^(3...)$: Anchor start and end and capture the content beginning with digit 3

    • (?:...): Don't capture content explicitly (captured within outer parenthesis)

    • 088|...|337|...: Match any of the three-digit values or

    • 5(?:...): First match 5 and then

    • 2[89]|[3-8][0-9]: Match either 2 followed by 8 or 9, or any digit from 3 to 8 followed by any digit (from 0 to 9)

    • \d{12}: Followed by exactly 12 any digits (\d is the same as [0-9])

    EDIT: Regarding your question about numbers starting with 2131 and 1800, it reads in your third reference page that those JCB card numbers are 15 digits long, while ones beginning with 35 are 16 digits long. If your specifications refers to only 16 digit long numbers, then you probably won't need to match those shorter ones.

    0 讨论(0)
提交回复
热议问题