jquery unobtrusive validation attributes reference?

JavascriptJquery

Javascript Problem Overview


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?

Javascript Solutions


Solution 1 - Javascript

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGauravView Question on Stackoverflow
Solution 1 - JavascriptBrianView Answer on Stackoverflow