If I have these strings:
\"abc\"
= false
\"123\"
= true
\"ab2\"
This will return true if input
is all numbers. Don't know if it's any better than TryParse
, but it will work.
Regex.IsMatch(input, @"^\d+$")
If you just want to know if it has one or more numbers mixed in with characters, leave off the ^
+
and $
.
Regex.IsMatch(input, @"\d")
Edit: Actually I think it is better than TryParse because a very long string could potentially overflow TryParse.