Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Input Email required property

Input Email required property

Input Email Object Reference Input Email Object

Example

Check whether the email field is required before submitting the form:

var x = document.getElementById("myEmail").required;

x

The output is:

true

Try it »


Definition and Usage

The required property is used to set or return whether the email field is required in the form.

This attribute reflects the HTML required attribute.


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the required attribute, except Internet Explorer 9 and earlier versions and the Safari browser.

Note: Internet Explorer 9 (and earlier IE versions) or Safari browser does not support the HTML element with type="email". .


Syntax

Return the required attribute:

emailObject

.required

Set the required attribute:

emailObject

.required=true|false

Attribute values

Value Description
true|false Describes whether the email field is a required part before the form is submitted.
  • true - the email field is a required part of the form
  • false - default. The email field is an optional part of the form.
  • |

    Technical Details

    Return Value: Boolean, returns true if the email field is a required part of the form, otherwise returns false.

    More examples

    Example

    Set the email field as a required part of the form:

    document.getElementById("myEmail").required = true;

    Try it »


    Related pages

    HTML Reference Manual: HTML required attribute


    Input Email Object Reference Input Email Object