I am trying to find the syntax for using a regular expression to only match four digit numbers and there has to be at least one number. Any Ideas? :)
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:
The way it is working right now is any number I put in the textbox I am getting the error message box. I only want the message box to pop up when the user enters invalid input like 10000, blank, ASDF, 0100 etc.
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:
Code:
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;
}
Comment