Creditcard verification with regex?

前端 未结 5 1054
星月不相逢
星月不相逢 2021-02-09 10:58

What is the right way to verify a credit card with a regex? If which one to use there are tons online. If not how to verify?

5条回答
  •  孤城傲影
    2021-02-09 11:23

    That depends on how accurate you want your pre-validation to be. To validate everything you can, you need to compute what the last digit of the card should be and compare to what is entered, which a RegEx cannot do.

    For the algorithm and other details see this link, which also provides a list of common number prefixes that you could validate against.

提交回复
热议问题