-
Notifications
You must be signed in to change notification settings - Fork 0
Default validation rules
The HTML Standard specifies a number of constraints that are implemented as standard as part of DomValidation, and are listed on this page with examples of how to use them.
-
requiredboolean attribute
Specifies whether a form field needs to be filled in before the form can be submitted. This attribute is boolean meaning to use it, it just needs to be present.
If any elements with the required are not filled in when the form is submitted, this will trigger an error with the hint message "This field is required".
Example:
<form>
<label>
<span>Your name, please</span>
<input name="your-name" required />
</label>
<button>Submit</button>
</form>-
minlengthattribute - integer, 0 or higher -
maxlengthattribute - integer, 0 or higher
Specified the minimum and maximum number of characters an element's value can contain.
If any elements with the minlength attribute are submitted with fewer than the required number of characters, this will trigger an error with the hint message "This field's value must contain at least X characters".
If any elements with the maxlength attribute are submitted with more than the required number of characters, this will trigger an error with the hint message "This field's value must not contain more than X characters".
Example:
<form>
<label>
<span>New password:</span>
<input type="password" name="new-password" minlength="12" />
</label>
</form>-
minattribute -
maxattribute
The min attribute defines the minimum that is acceptable and valid for the input containing the attribute. The max attribute defines the maximum value that is acceptable and valid for the input containing the attribute.
Different input types have different minimum/maximum syntaxes.
Example (from MDN):
| Input type | Syntax | Example |
|---|---|---|
| date | yyyy-mm-dd | |
| month | yyyy-mm | |
| week | yyyy-W## | |
| time | hh:mm | |
| datetime-local | yyyy-mm-ddThh:mm | |
| number | ||
| range |
DomTemplate is a separately maintained component of PHP.Gt WebEngine.