Is there any way to use @Range to validate a range of dates in Regula? (ditto @Min and @Max)
Or do I need to use @Custom?
@Range(min=
and
@Range(max=
do not seem to accept anything of the type Date - only numbers or strings.
Is there any way to use @Range to validate a range of dates in Regula? (ditto @Min and @Max)
Or do I need to use @Custom?
@Range(min=
and
@Range(max=
do not seem to accept anything of the type Date - only numbers or strings.
On
I found that the following hack works:
I added a second, hidden input that contains the date entered in the format of Date.getTime():
<input type="hidden" data-bind="value: myDateValue.getTime()" ... />
(I'm using Kendo MVVM, but I'm sure other MVVM libraries can handle the same approach)
Then for the constraint, on server side (ASP.NET MVC in my case) I'm generating the Unix time for the min and max:
@Range(min="<%= (dateTime1 - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds %>",
max="<%= (dateTime2 - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds %>")
EDIT
Need to use .TotalMilliseconds - and even so there's some unexplained discrepancy.
Unfortunately
@Rangeonly accepts numbers. I think you can do something like this though:This ensures that the date is after
2000/1/1and before2010/1/1(i.e., in between). I didn't document thedateparameter because I don't think I had implemented it when I wrote the documentation. Sorry; the documentation is a bit behind because I'm working on rolling version 1.3 of Regula out, that will have a lot more goodies. I'll be getting started on updating the documentation soon!