I am trying to validate my WPF programme in C# to check that the user has inputted a date into my DatePicker event. If the user has not input the date I would like it to let the user re input the data before running the whole programme again. I would also like it to do the same if the user has input a numer of less that 1 or more than 10. However at the moment it simply continues on with the rest of the programme causing it to break later on.
My 'textbox' event is called UserInput and my DatePicker is called 'RequestedDate'
My code:
if (int.TryParse(UserInput.Text, out numberEntered))
{
while (DateRequested.SelectedDate == null)
{
MessageBox.Show("You have not input a valid date");
Output.Text = "Please try again";
}
while (numberEntered < 1 || numberEntered > 10)
{
MessageBox.Show("You can only book tickets with values more than one or less than 10");
Output.Text = "Please try again";
break;
}
Output.Text = "Number of tickets selected: " + UserInput.Text + "Date: " + DateRequested.Text;
}