Feature and documentation request for VAB

Topics: Validation Application Block
Mar 9, 2007 at 6:28 PM
Edited Mar 9, 2007 at 7:37 PM
Two things:
It would be nice if you could the regular expression associated with a validator back out. Since the VAB does not provide client side validation, we are combining it with normal asp validators. Before using the VAB we had our own custom written validation block (which looked surprisingly similar, but only handled regular expression validators). However, the one advantage it had is that the programmer could access the regular expression stored with a particular validator. This was useful so it could then be assigned to an asp:regularexpresionvalidator validation expression.

The advantage was that the regular expression only needed to be defined in one place. It allowed us to loosely tie together the client side and server side validators - at least we could be sure they were using the same validation expression.

It seems that the VAB regular expression validators store the regular expression, but do not expose it. It would be nice if they did expose that RegEx so it too could be fed into an asp:regularexpressionvalidator validation expression.

It would be nice if the documentation for the RelativeDateRangeValidator showed how to validate that a field was greater than DateTime.Now.Date. This seems to be a common theme in validation (i.e. not letting people take an action in the past). I thought it should be simple to do, but had trouble figuring this out. As it is common, it would be nice to have an example of this type.

We tried this:
DateTimeRangeValidator(DateTime.Now.Date, RangeBoundaryType.Inclusive, DateTime.Now.Date, RangeBoundaryType.Ignore, MessageTemplate="Registration must be in the future")
public DateTime RegistrationDate { get { return this.registrationDate; } set { this.registrationDate = value; } }

but DateTimeRangeValidator does not allow non constants.

However, with the RelativeDateRangeValidator it seems that you cannot choose to ignore time - and only look at the date.

For example, assume that we even don't want today's date. We want to test the date entered must be greater than or equal to tomorrow. It seems that any way we construct a RelativeDateRangeValidator - it still looks at time and therefore we get incorrect results.

We tried:
RelativeDateTimeValidator(1, DateTimeUnit.Day, RangeBoundaryType.Exclusive, 0, DateTimeUnit.Day, RangeBoundaryType.Ignore, MessageTemplate="Registration must be in the future")
public DateTime RegistrationDate { get { return this.registrationDate; } set { this.registrationDate = value; } }

But if it is currently 3/8/2007 at 11:30am, then 3/9/2007 at 11:00am is flagged as not valid. So we can't seem to validate based on only date - time is always included.

Are we approaching this incorrectly - or is this not possible using the Validators available in the VAB?

How about something even as simple as validating that a date matches today's date? Is that possible?

Mar 9, 2007 at 10:36 PM
Re 1: Good catch. We changed the accessibility of RegexValidator.GetPattern() from private to public to support this scenario.

Re 2: This looks like a sensible request but it's too late for us to mkae any changes now. The DateTimeRangeValidator will support this programmatically, but as you've discovered it isn't possible to use non-constant values in attributes or configuration. Probably the best thing to do (assuming you're using attributes) is to build a new attribute that wraps the DateTimeRangeValidator to encapsulate the concept of "today" rather than "now". You could do something similar with configuration but it would be a bit more work.

Mar 12, 2007 at 10:22 PM
Thanks for making the change on the GetPattern() function.

I will look at either using the DateTimeRangeValidator programmatically, or writing our own (we have several of our own that we have already written, so doing more is not an issue, it just seemed like this was one that many people would have a use for)