We use data annotations in combination with the jQuery.validate.unobtrusive plugin for one of our applications and came across a unique, what appears to be a bug, today.
View Model Property
[Required(ErrorMessage = "You must specifiy a point value for the contest entry")]
[Min(5, ErrorMessage = "The point value must be at least 5 points for this contest")]
[DisplayName("Points required for entry:")]
public int RequiredPoints { get; set; }
View
<li class="reqpoints">@Html.LabelFor(x => x.RequiredPoints) @Html.TextBoxFor(x => x.RequiredPoints)</li>
Resulting HTML
<li class="reqpoints">
<label for="RequiredPoints"></label>
<input id="RequiredPoints" class="input-validation-error" type="text" value="10" name="RequiredPoints" data-val-required="You must specifiy a point value for the contest entry" data-val-range-min="5" data-val-range="The point value must be at least 5 points for this contest" data-val-number="The field Points required for entry: must be a number." data-val="true"></input>
</li>
This works great if the number entered into the textbox is 5-9 or if the first digit is 5 or greater. Any number from 10 through 49, 100-499, 1000-4999, etc gets rejected with the error message that it must be at least 5 points, almost as if it is truncating the last digits. This is not going to the server and coming back, it is the jQuery validation portion that is firing off. Has anyone seen an issue using Min()
with a single integer value like this?
I should note we use this somewhere else where the minimum value is 100 and have no issues (that I am aware of) of any number greater than 100 being rejected.
Relevant versions:
- jQuery - 1.8.4
- jQuery.Validation - 1.12.0
- jQuery.validation.unobtrusive - 3.1.2
Update
If I change the Min
attribute to have a minimum of 10, everything works as expected. Additionally, if I use the Range(5,99999)
data attribute, then all values seem to work as expected as well. It appears that the combination of jQuery 1.8.4 and the latest versions of the validation plugins might have an issue with single digit minimum validation.