我有這樣的正則表達式驗證CC號碼:正則表達式驗證CC數不驗證JCB卡正確
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$
它適用於幾乎所有的,但它沒有幾個人。快速瀏覽一下我所做的這個測試:
#American Express
370517943574132 -> passed
372714451742486 -> passed
370010255141385 -> passed
341263547614307 -> passed
343874494387669 -> passed
#VISA
4024007125780444 -> passed
4439944519233615 -> passed
4658355677043536 -> passed
4532926168018906 -> passed
4532249806735728 -> passed
#MasterCard
5524097521691644 -> passed
5367170623993901 -> passed
5553103980950937 -> passed
5549194987582424 -> passed
5141794881796756 -> passed
#JCB 15 digits
180078244412845 -> passed
210013400722277 -> not passed
210082510016250 -> not passed
180056142071970 -> passed
210043823226606 -> not passed
#JCB
3158822586903214 -> not passed
3088687202983378 -> not passed
3158899851849561 -> not passed
3096803356450490 -> not passed
3337852908456769 -> not passed
#Dinners Club
30193567772121 -> passed
30131361923813 -> passed
30198560976769 -> passed
30260244203356 -> passed
36297440059376 -> passed
問題在哪裏?任何能給我一些幫助嗎? Here就是一個例子Regex101
您不必在所有匹配JCB號的一個分支。我爲'JCB15 digits'增加了'2100'替代方案:https://regex101.com/r/mV2lN7/1,剩下的就是你需要添加的內容。 –