ElementInternals: checkValidity() method

Baseline 2023
Newly available

Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Syntax

js
checkValidity()

Parameters

None.

Return value

A boolean value, true if the element meets all validation constraints.

Exceptions

NotSupportedError DOMException

Thrown if the element does not have its formAssociated property set to true.

Examples

In the following example ElementInternals.setValidity() is used to indicate that the element does not meet validation rules. Calling checkValidity() returns false. After calling setValidity again, this time indicating that all rules are marked false, checkValidity() returns true.

js
let element = document.getElementById("join-checkbox");
element.internals_.setValidity({ valueMissing: true }, "my message");
console.log(element.internals_.checkValidity()); / false
element.internals_.setValidity({});
console.log(element.internals_.checkValidity()); / true

Specifications

Specification
Product help
  • Instance properties
    1. ariaChecked
    2. ariaColSpan
    3. ariaExpanded
    4. ariaLabel
    5. ariaMultiLine
    6. ariaPosInSet
    7. ariaRequired
    8. ariaRowIndexText
    9. ariaSort
    10. ariaValueText
    11. shadowRoot
    12. willValidate
  • Instance methods
    1. setValidity()
  • Related pages for Web Components
    1. Element.attachShadow()
    2. Event.composedPath
    3. Node.getRootNode()
    4. Window.customElements
  • ","source":{"folder":"en-us/web/api/elementinternals/checkvalidity","github_url":"https://github.com/mdn/content/blob/main/files/en-us/web/api/elementinternals/checkvalidity/index.md","last_commit_url":"https://github.com/mdn/content/commit/ce10da0e9d23d241b175d8d68bf93507734b7c48","filename":"index.md"},"summary":"The checkValidity() method of the ElementInternals interface checks if the element meets any constraint validation rules applied to it.","title":"ElementInternals: checkValidity() method","toc":[{"text":"Syntax","id":"syntax"},{"text":"Examples","id":"examples"},{"text":"Specifications","id":"specifications"},{"text":"Browser compatibility","id":"browser_compatibility"}],"baseline":{"baseline":"low","baseline_low_date":"2023-03-27","support":{"chrome":"77","chrome_android":"77","edge":"79","firefox":"98","firefox_android":"98","safari":"16.4","safari_ios":"16.4"}},"browserCompat":["api.ElementInternals.checkValidity"],"pageType":"web-api-instance-method"}}

    Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

    Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant