Javascript jquery不显眼的验证属性参考?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11124880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 04:35:39  来源:igfitidea点击:

jquery unobtrusive validation attributes reference?

javascriptjquery

提问by Gaurav

Where i can find the reference for Unobtrusive jquery validation attributeslike

在哪里可以找到Unobtrusive jquery 验证属性的参考,例如

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

data-val-length等。data-val-required我想要这些属性的完整列表。是

there any single place where i can find this?

有什么地方可以找到这个吗?

回答by Brian

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.

我发现的最接近的事情是在文章中我学到了关于 jQuery unobtrusive validation 的一些事情。这篇文章有更好的格式和更多信息,但我已经在这里复制了好的部分,以防它消失。

  • 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).
  • 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": 要求一个字段是一个 url(我不推荐这个,因为它接受太多——我更喜欢使用正则表达式)。


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-foris the control's name, not id.

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