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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top