YouTip LogoYouTip

Prop Number Required

HTML DOM Input Number required Attribute

HTML DOM Input Number required Attribute

-- Learning is not just about technology, but also about dreams!

JavaScript Reference Manual

Overview

JavaScript Objects

Browser Objects

DOM Objects

HTML Objects

<input> - month

<input> - range

Input Number required Attribute

Input Number Object Reference Manual Input Number Object

Example

Check if the number field is required before submitting the form:

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

x output result:

true

Try it yourself Β»


Definition and Usage

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

This property reflects the HTML required attribute.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the required attribute.

Note: Internet Explorer 9 and earlier versions do not support the <input> element with the type="number" attribute.


Syntax

Return the required property:

numberObject.required

Set the required property:

numberObject.required=true|false

Property Values

Value Description
true|false Specifies whether the number field is a required part of the form before submission.
* true - The number field is a required part of the form.
* false - Default. The number field is an optional part of the form.

Technical Details

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

More Examples

Example

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

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

Try it yourself Β»


Related Pages

HTML Reference Manual: HTML <input> required Attribute


Input Number Object Reference Manual Input Number Object

← Prop Number TypeProp Number Readonly β†’