private void txtmembdate_Validating(object sender, CancelEventArgs e) { DateTime dob; // DOB is required and must be a valid date if (!DateTime.TryParse(txtmembdate.Text, out dob)) { errorProviderbdate.SetError(txtmembdate, "Must be a date/time value"); e.Cancel = true; return; } // Must be 18 or older if (dob > DateTime.Now.AddYears(-18)) { errorProviderbdate.SetError(txtmembdate, "Must be 18 or older"); e.Cancel = true; return; } // DOB is valid errorProviderbdate.SetError(txtmembdate, ""); }
DateTime
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)