Question

The existing .Net range attribute validator only accepts static string values. I would like to create a validator that accepts dynamic values. For example I would like the age range to be 16 years to 200. If I input the minimum birthday as 1996-today in a year from now the minimum age is now 17 and will continue to rise year after year. Is this possible or should I just validate this manually in the view model? Edit: I'm not using asp here, this is a desktop application.

Was it helpful?

Solution

I fixed this by using a CustomValidationAttribute. This Attribute is basically just a static method that does the validating and I put the min/max birthdate values in the method. Unfortunately this is the only way I could find to deal with the issue of wanting the dates to be dynamic.

OTHER TIPS

DONE IT

 $("#YourField").data("val-range-max", $("#AFieldThatStoresTheMaxValue").value());

});

AFieldThatStoresTheMaxValue => could be a HiddenFor...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top