|
-
May 21st, 2007, 08:46 AM
#1
Thread Starter
Addicted Member
How to check string for alphanumeric, isnumeric, etc [RESOLVED]
I have a text box on my form, for which the input from the user is "correct" if it is a number of things... Certain phrases, and in some cases certain ranges of numbers. When I have the if statements checking the .Text of the textbox, they are using:
C# Code:
if (text1.Text == "test" || System.Convert.ToInt32(text1.Text.Trim()) >= 0)
{
// Do stuff
}
The problem is that if a string or non-number is entered, the conversion throws an exception saying inproper format (I think that is what it said but it is because it is trying to convert a string/non-number to an integer). I have worked around it using try and catch around the if statements, but that can't be the right way, to just ignore the exceptions? If this were VB I would have done isnumeric first to check for a numeric input. What can I do in C#?
Last edited by pjrage; May 22nd, 2007 at 12:27 PM.
Reason: RESOLVED
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|