草案
此页面不完整。

只读 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 属性。

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.

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 .

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 type Expected value
email x@y or x@y.z email address, with or without TLD
url x: or x://y.z protocol or full URL with protocol

范例

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

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 将是 true .

规范

规范 状态 注释
HTML 实时标准
The definition of 'ValidityState.typeMismatch' in that specification.
实时标准
HTML 5.1
The definition of 'ValidityState.typeMismatch' in that specification.
推荐
HTML5
The definition of 'ValidityState.typeMismatch' in that specification.
推荐

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

No compatibility data found. Please contribute data for "api.ValidityState.typeMismatch" (depth: 1) to the MDN 兼容性数据存储库 .

另请参阅

元数据

  • 最后修改:

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1