How to check for string as alpha or numeric??

  • Thread starter Thread starter trint
  • Start date Start date
T

trint

How can I check this to see if it is a string representation of a
number, or if it is actually just text?
Convert.Int32(AlphaNumeric); returns the error for wrong format if it's
alpha. I just want to know if it is letters or numbers in the string.

string AlphaNumeric = "US";

Thanks,
Trint
 
I would look into the Regex class and regular expressions. You can use
Regex to check the string against any pattern you like, "all digits"
being one possible pattern, which would look like this:

if (Regex.IsMatch(myString, @"^\d+$")) ...

which will match a string containing one or more digits and nothing
else.
 
Back
Top