Regular Expression to describe Credit Card expiry (valid thru) date

后端 未结 3 532
长情又很酷
长情又很酷 2020-12-11 09:47

I need a regular expression to validate credit card expiry date. Note that the format of the \"date\" is MM/YY where YY is the year without century and MM is the month (from

3条回答
  •  青春惊慌失措
    2020-12-11 10:48

    currentDate = new Date()
    currenYear = currentDate.getFullYear()
    
    ones_number = currenYear % 10
    tens_number = Math.floor(currenYear % 100 / 10)
    
    regrexStr   = '^((0[1-9])|(1[0-2]))\/?((' + tens_number + '[' + ones_number + '-9])|([' + (tens_number + 1) + '-9][0-9]))$'
    

    this can run from now on to until the end of the Earth with format MMYY or MM/YY

提交回复
热议问题