ValidityState.typeMismatch - Web APIs 编辑

Draft

This page is not complete.

The read-only typeMismatch property of a ValidityState object indicates if the value of an <input>, after having been edited by the user, does not conform to the constraints set by the element's type attribute.

If the type attribute expects specific strings, such as the email and url types and the value don't doesn't conform to the constraints set by the type, the typeMismatch property will be true.

The email input type expects one or more valid email addresses, depending on whether the multiple attribute is present. A valid email address includes an email prefix and a domain, with or without a top level domain. If the value of the email input is not an empty string, a single valid e-mail address, or one or more comma separated email address if the multiple attribute is present, there is a typeMismatch.

The url input type expects one or more valid email URLs, depending on whether the multiple attribute is present. A valid URL includes a protocol, optionally with an IP address, or  an optional subdomain, domain, and top level domain combination. If the value of the URL input is not an empty string, a single valid URL, or one or more comma separated URLS if the multiple attribute is present, there is a typeMismatch.

 type attribute conformance
Input typeValueExpected value
emailx@y or x@y.zemail address, with or without TLD
urlx: or x://y.zprotocol or full URL with protocol

Examples

Given the following:

<p>
 <label>
    Enter an email address:
    <input type="email" value="example.com"/>
 </label>
</p>
<p>
 <label>
     Enter a URL:
     <input type="url" value="example.com"/>
  </label>
</p>
input:invalid {
  border: red solid 3px;
}

The above each produce a typeMismatch because the email address is just a domain and the URL has no protocol

The typeMismatch occurs when there is a disconnect between the value expected via the type attribute and the data that is actually present. The typeMismatch is only one of the many possible errors and is only relevant for the email and url types. When the value provided doesn't match the expected value based on the type for other input types, you get different errors. For example, if the number input value is not a floating point number, the badInput is true. If the email is required but is empty, the valueMissing will be true.

Specifications

SpecificationStatusComment
HTML Living Standard
The definition of 'ValidityState.typeMismatch' in that specification.
Living Standard
HTML 5.1
The definition of 'ValidityState.typeMismatch' in that specification.
Recommendation
HTML5
The definition of 'ValidityState.typeMismatch' in that specification.
Recommendation

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:122 次

字数:6605

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文