I have a simple validator that should check if the the date format is incorrect. I am doing testing and enter 2/14/201… which gets passed through my validator as 2/14/0201. How do I prevent this and jump to e.IsValid = false;?
protected void rangeVal(object sender, ServerValidateEventArgs e)
{
DateTime dateCheck = txtDate1.Text.Trim();
DateTime select;
if (DateTime.TryParse(dateCheck, out select))
e.IsValid = true;
else
e.IsValid = false;
}
Should dateCheck be a string instead of a DateTime?
If only dates > the year 1900 are valid, you could try:
and that might suit your requirement.