regular expression matching a 3 or 4 digit cvv of a credit card

后端 未结 1 618
北荒
北荒 2021-02-05 02:21

I really don\'t know regexp yet, but sooner or later I will read and learn. But for now I need a regular expression matching a 3 or 4 digit cvv of a credit card so I can valida

1条回答
  •  [愿得一人]
    2021-02-05 03:07

    To match 3 or 4 digits, use the following regular expression:

    /^[0-9]{3,4}$/
    

    Explanation:

    • ^: Start of string anchor
    • [0-9]: Digit between 0 and 9 (you could also use \d here)
    • {3,4}: A quantifier meaning between 3 and 4.
    • $: End of string anchor

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