|
-
July 9th, 2009, 08:28 PM
#3
Re: Input Type Check
You can do a regex check first to avoid some errors, and it's regex, so it matches or it doesn't, no error unless text field is blank or expression is bad.
Of course, my code might not be the solution you are looking for, but it's a step. You can change the event to whatever you like.
Code:
namespace CodeGuru
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonCheck_Click(object sender, EventArgs e)
{
Regex check = new Regex("[0-9]+");
String text = textBox1.Text;
if (text.Length > 0)
{
Match match = check.Match(text);
Int32 guess = Int32.Parse(match.Value);
MessageBox.Show(guess.ToString());
}
}
}
}
Last edited by code?; July 9th, 2009 at 08:39 PM.
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
|