jQuery的非侵入式验证属性参考? [英] jquery unobtrusive validation attributes reference?

查看:73
本文介绍了jQuery的非侵入式验证属性参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里可以找到不引人注目的jquery验证属性的参考,例如

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

data-val-length 需要数据值等。我想要这些属性的完整列表。

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?

推荐答案

我找到的最接近的东西是在文章我从jQuery非侵入式验证中学到了一些东西。这篇文章具有更好的格式和更多信息,但是我在这里复制了一些不错的部分,以防万一它消失了。

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 :对此元素启用不干扰验证(应该在要验证的每个输入元素上)

  • data-val-required = ErrMsg :要求输入,并显示ErrMsg

  • data-val-length = ErrMsg data-val-length-min = 5 data-val-length-max = 15 :设置所需的字符串长度和相关的错误消息。

  • data-val-number = ErrMsg :使字段必须为数字。

  • data-val-date = ErrMsg :需要一个字段成为约会(我不建议这样做,因为它接受了太多–我更喜欢使用正则表达式)。

  • data-val-equalto = ErrMsg data-val-equalto-other = Fld :要求一个字段与另一个字段匹配(例如密码确认。Fld是jQuery选择器

  • data-val-regex = ErrMsg data-val-regex-pattern = ^ regex $ :要求该字段匹配正则表达式模式。

  • data-val-email = ErrMsg :要求将字段作为电子邮件(我不建议这样做,因为它接受的太多-我更喜欢使用正则表达式)。

  • data-val-url = ErrMsg :要求字段为网址(我不建议这样做,因为它接受的太多-我更喜欢使用正则表达式)。

  • 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).

更新:

用于显示验证消息,为要验证的每个控件添加一个容器。

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>

请注意, data-valmsg-for 为控件的名称,而不是ID。

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

这篇关于jQuery的非侵入式验证属性参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆