I have a form with a textbox and I am trying to using regular expression
matching to verify the form. I don't want the user to be able to leave the
textbox blank, it must be a real number from 0 to 9999. The user can't
leave the text box blank. The way it is working now is any number I put
in the textbox it is popping up the MessageBox "Enter a one to four digit
number!" If the user enters invalid data I want the button event to return
to the form method and stop executing.
Here's the code:
Expand|Select|Wrap|Line Numbers
- private void button2_Click(object sender, EventArgs e)
- {
- //invalid input checking
- if (regex_match(DelayA1Pulse6.Text))
- {
- return;
- }
- }
- public static bool regex_match(string s)
- {
- Regex checkNumber = new Regex("/b/d{1,4}/b");
- if (checkNumber.IsMatch(s))
- {
- return false;
- }
- else
- MessageBox.Show("Enter a one to four digit number!");
- return true;
- }