L
-Lost
Can I validate that input is numeric without regular expressions?
I've just begun learning C# as of a week ago, so bear with me if I
utilize incorrect terminology (but feel free to correct me, please).
Anyway, I am trying to find a "standard" way of validating input to
the program. I need ONLY numeric arguments. I can do this with
regular expressions, but was wondering if there were any other
(possibly more correct) ways of doing it.
I was currently doing this:
scores.GetType().ToString() == typeof(String).FullName
So, it works to the extent that it will not allow me to declare an
instance of my custom class and pass string arguments to the
constructor.
However, I cannot pass command-line arguments because all console
input is read as string literals.
Or the Regex method:
Regex numericOnlyRegExp = new Regex("[a-z|A-Z]");
numericOnlyRegExp.IsMath("abc"); // if true return false
But I'd like to avoid this if possible (for no particular reason).
So... ? Thanks for any and all help!
I've just begun learning C# as of a week ago, so bear with me if I
utilize incorrect terminology (but feel free to correct me, please).
Anyway, I am trying to find a "standard" way of validating input to
the program. I need ONLY numeric arguments. I can do this with
regular expressions, but was wondering if there were any other
(possibly more correct) ways of doing it.
I was currently doing this:
scores.GetType().ToString() == typeof(String).FullName
So, it works to the extent that it will not allow me to declare an
instance of my custom class and pass string arguments to the
constructor.
However, I cannot pass command-line arguments because all console
input is read as string literals.
Or the Regex method:
Regex numericOnlyRegExp = new Regex("[a-z|A-Z]");
numericOnlyRegExp.IsMath("abc"); // if true return false
But I'd like to avoid this if possible (for no particular reason).
So... ? Thanks for any and all help!