Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
107
rated 0 times [  108] [ 1]  / answers: 1 / hits: 39180  / 12 Years ago, wed, june 20, 2012, 12:00:00

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?


More From » jquery

 Answers
43

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.


[#84770] Wednesday, June 20, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaia

Total Points: 574
Total Questions: 109
Total Answers: 110

Location: Malaysia
Member since Wed, May 11, 2022
2 Years ago
;