1

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.

John the Ripper
  • 2,389
  • 4
  • 35
  • 61
  • Please check this thread http://stackoverflow.com/questions/9099143/asp-validator-determine-if-age-is-within-range and also http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html – Habib May 05 '12 at 17:41
  • Those will only work in ASP. My application is a desktop app. thanks – John the Ripper May 05 '12 at 17:55

2 Answers2

0

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.

John the Ripper
  • 2,389
  • 4
  • 35
  • 61
0

DONE IT

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

});

AFieldThatStoresTheMaxValue => could be a HiddenFor...

Community
  • 1
  • 1
Cătălin Rădoi
  • 1,804
  • 23
  • 43