A date ending in all zeros doesn't cause an error in MaskedEdit validator. In short, 01/01/0000 should show the MinimumValueMessage but doesn't.
<asp:MaskedEditValidator MinimumValue="01/01/1900" MinimumValueMessage="<b>Out of Range</b><br />Date of Birth cannot be before 01/01/1900." MinimumValueBlurredText="*"/>
The root cause is System.DateTime.Parse throws an exception since c# MinDate is January 1, 0001.
The exception causes the validator to NOT call the callout.
I propose that line 795 of ./Server/AjaxControlToolkit/MaskedEdit/MaskedEditValidator.cs
case MaskedEditType.DateTime:
case MaskedEditType.Date:
case MaskedEditType.Time:
{
DateTime dtval = System.DateTime.Parse(Target.Text, ControlCulture);
becomes:
case MaskedEditType.DateTime:
case MaskedEditType.Date:
case MaskedEditType.Time:
{
DateTime dtval;
try
{
dtval = System.DateTime.Parse(Target.Text, ControlCulture);
}
catch
{
// a 0000 year causes an exception, set to MinValue
dtval = System.DateTime.MinValue;
}
I'm not sure whether there's other places which would need to be changed and whether this is the optimal approach. It's working for me.
<asp:MaskedEditValidator MinimumValue="01/01/1900" MinimumValueMessage="<b>Out of Range</b><br />Date of Birth cannot be before 01/01/1900." MinimumValueBlurredText="*"/>
The root cause is System.DateTime.Parse throws an exception since c# MinDate is January 1, 0001.
The exception causes the validator to NOT call the callout.
I propose that line 795 of ./Server/AjaxControlToolkit/MaskedEdit/MaskedEditValidator.cs
case MaskedEditType.DateTime:
case MaskedEditType.Date:
case MaskedEditType.Time:
{
DateTime dtval = System.DateTime.Parse(Target.Text, ControlCulture);
becomes:
case MaskedEditType.DateTime:
case MaskedEditType.Date:
case MaskedEditType.Time:
{
DateTime dtval;
try
{
dtval = System.DateTime.Parse(Target.Text, ControlCulture);
}
catch
{
// a 0000 year causes an exception, set to MinValue
dtval = System.DateTime.MinValue;
}
I'm not sure whether there's other places which would need to be changed and whether this is the optimal approach. It's working for me.