Regex to check for 4 consecutive numbers

前端 未结 3 732
梦谈多话
梦谈多话 2020-12-11 17:32

Can I use

\\d\\d\\d\\d[^\\d]

to check for four consecutive numbers?

For example,

411112 OK

455553 OK

1200

3条回答
  •  独厮守ぢ
    2020-12-11 18:02

    Should the numbers be part of a string, or do you want only the four numbers. In the later case, the regexp should be ^\d{4}$. The ^ marks the beginning of the string, $ the end. That makes sure, that only four numbers are valid, and nothing before or after that.

提交回复
热议问题