date validity
C#
3
Posts
3
Posters
0
Views
1
Watching
-
In a textbox a date is entered. How can you check if this is a valid date or infact a date at all? Thanks
-
In a textbox a date is entered. How can you check if this is a valid date or infact a date at all? Thanks
You can do that quite easily by writing your code inside a try/catch block like below:
try
{
DateTimetmp
= DateTime.Parse(this.textBox1.Text);
}
catch (Exception exc)
{
MessageBox.Show("This is not a valid date\n\nError Message: " + exc.Message);
return;
}
MessageBox.Show("Date is valid");Regards, Polis Can you practice what you teach?