0

When constructing an input an ASP.NET MVC 3 view which uses jQuery.validate

<input 
  type="text" 
  class="text-box single-line" 
  id="ReserveQuantity" 
  name="ReserveQuantity" 
  data-val="true" 
  data-val-required="The Reserve Quantity field is required." 
  data-val-number="This value must be numeric"
>

this is markup that would be used for for a ReserveQuantity input. In addition to these parameters, what data- annotation should I use in order to make sure only a certain numeric range is acceptable here without manual validation?

2 Answers 2

1

There is actually a built in data annotation for ranges, and it looks like this:

data-val-range="The field must be in range 0 to 104." 
data-val-range-min="0" 
data-val-range-max="104"
Sign up to request clarification or add additional context in comments.

Comments

0

http://docs.jquery.com/Plugins/Validation/Methods/range#range

var minVal = 10, maxVal = 20;

$("#myform").validate({
    rules: {
        ReserveQuantity: {
            required: true,
            range: [ minVal, maxVal ]
        }
    }
});

2 Comments

How will this affect the current data- annotations?
I don't think it affects it them all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.