if i have this string:
12345
= true
123a45
= false
abcde
= false
how to do it in C#?
Regex.IsMatch(sinput,@"\d+");
to match a string containing just digits. If you forgot an optional digit in the question, use this:
Regex.IsMatch("+12345", @"[+-]?\d+");
If you want to avoid RegEx, then you can use the built-in char
methods:
bool allDigits = s.All(c => char.IsDigit(c));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With