Regex for numbers only

后端 未结 18 2638
野性不改
野性不改 2020-11-22 03:29

I haven\'t used regular expressions at all, so I\'m having difficulty troubleshooting. I want the regex to match only when the contained string is all numbers; but with the

18条回答
  •  情书的邮戳
    2020-11-22 04:03

    If you need to tolerate decimal point and thousand marker

    var regex = new Regex(@"^-?[0-9][0-9,\.]+$");
    

    You will need a "-", if the number can go negative.

提交回复
热议问题