I have a Date field on my MVC UI called "startDate", the user selects the date using jquery date picker. Since I wanted to confirm that the selected date should not be 2 months and 2 months in the future.
I wrote the code below to confirm the date.
public sealed class DateAttribute : DataTypeAttribute
{
public DateAttribute() : base(DataType.Date)
{
}
public override bool IsValid(object value)
{
DateTime inputDate = Convert.ToDateTime(value, CultureInfo.CurrentCulture);
if (inputDate.Date >= DateTime.Now.Date.AddMonths(-2) && inputDate.Date <= DateTime.Now.Date.AddMonths(2))
return true;
return false;
}
}
But the problem is that it goes to the server to check the date field. how can i achieve this with client validation.
Thanks, -Naren
source
share