69

Where i can find the reference for Unobtrusive jquery validation attributes like

data-val-length , data-val-required etc..I want the full list of these attributes. Is

there any single place where i can find this?

0

2 Answers 2

139

The closest thing I've found is in the article Some things I’ve learned about jQuery unobtrusive validation. The article has better formatting and more info, but I've copied the good parts here in case it disappears.

  • data-val="true": enable unobtrusive validation on this element (should be on every input element you want to validate)
  • data-val-required="ErrMsg": makes the input required, and shows the ErrMsg
  • data-val-length="ErrMsg", data-val-length-min="5", data-val-length-max="15": sets required string length and associated error message.
  • data-val-number="ErrMsg": makes a field required to be a number.
  • data-val-date="ErrMsg": requires a field to be a date (I do not recommend this, as it accepts too much – I prefer to use regex).
  • data-val-equalto="ErrMsg", data-val-equalto-other="Fld": requires one field to match the other (such as password confirm. Fld is a jQuery selector
  • data-val-regex="ErrMsg", data-val-regex-pattern="^regex$": Requires the field to match the regex pattern.
  • data-val-email="ErrMsg": requires a field to be a email (I do not recommend this, as it accepts too much – I prefer to use regex).
  • data-val-url="ErrMsg": requires a field to be a url (I do not recommend this, as it accepts too much – I prefer to use regex).

Update:

For displaying the validation message, add a container for each control you want to validate.

<div class="field-validation-valid" data-valmsg-for="controlName" data-valmsg-replace="true"></div> 

Note that data-valmsg-for is the control's name, not id.

Sign up to request clarification or add additional context in comments.

2 Comments

Here is the content from the link: web.archive.org/web/20130919030425/http://…
Can add to this data-val-range="errorMessage", data-val-range-min="0" and data-val-max="100"
0

It's Working code. I,m already used at this time.

var NoOfEMI = $('#venderForm [data-valmsg-for="NoOfEMI"]').empty(); NoOfEMI.html("Number of the EMI is required"); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.