Regex for just only numbers

后端 未结 3 524
既然无缘
既然无缘 2021-01-27 14:06

I haven\'t used regular expressions soo much, so I\'m having difficulty . I want regex that only validates that the field contains digits, but that does not care about how many.

相关标签:
3条回答
  • 2021-01-27 14:50

    It's OK. You can just use ^\d+$ for all it matters anyway.

    0 讨论(0)
  • 2021-01-27 14:53

    Yes, this regex is perfectly valid and does what you think it does, although if your regex engine supports this you could use \d, whichs stands for [0-9].

    0 讨论(0)
  • 2021-01-27 14:53

    A simpler regex would be to invert your match and check for non-digit numbers: \D.

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