Regex to match a 2-digit number (to validate Credit/Debit Card Issue number)

前端 未结 3 1014
青春惊慌失措
青春惊慌失措 2021-02-02 08:46

I would like to use regex to match a string of exactly 2 characters, and both of those characters have to be between 0 and 9. The string to match against would be coming from a

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-02 09:32

    You can use the start (^) and end ($) of line indicators:

    ^[0-9]{2}$
    

    Some language also have functions that allows you to match against an entire string, where-as you were using a find function. Matching against the entire string will make your regex work as an alternative to the above. The above regex will also work, but the ^ and $ will be redundant.

提交回复
热议问题