credit card input validation using regular expression in javascript

后端 未结 3 695
北恋
北恋 2021-02-14 12:35

I\'ve been trying to get this done but no success. I am using regular expression to validate the credit card number entered by user based on the type of credit card selected thr

3条回答
  •  半阙折子戏
    2021-02-14 13:12

    This should do the job

    var cc = /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|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}|62[0-9]{14})$/
    
    cc.test(card_number)
    

    Source: vee-validate repo

提交回复
热议问题