How to check if my string only numeric

后端 未结 7 2066
臣服心动
臣服心动 2020-12-18 17:49

How I can check if my string only contain numbers?

I don\'t remember. Something like isnumeric?

7条回答
  •  臣服心动
    2020-12-18 18:32

    If you want to use Regex you would have to use something like this:

    string regExPattern = @"^[0-9]+$";
    System.Text.RegularExpressions.Regex pattern = new System.Text.RegularExpressions.Regex(regExPattern);
    return pattern.IsMatch(yourString);
    

提交回复
热议问题