HTML5 HTML5 Forms and Input Types 2 — Questions and Answers
Question 1: Which HTML5 attribute allows you to validate an input field value against a regular expression?
- pattern (Correct answer)
- validate
- regex
- format
Correct answer: pattern
The pattern attribute specifies a regular expression that the input's value must match for the form to be valid.
Question 2: What does the 'novalidate' attribute on a <form> element do?
- Disables built-in HTML5 form validation (Correct answer)
- Prevents the form from submitting
- Clears all form fields
- Hides validation error messages
Correct answer: Disables built-in HTML5 form validation
The novalidate attribute specifies that the form should not be validated when submitted, bypassing HTML5 constraint validation.
Question 3: Which HTML5 input type is used specifically for entering a URL with format validation?
- url (Correct answer)
- link
- href
- web
Correct answer: url
The input type='url' validates that the entered value is a properly formatted URL including the protocol.
Question 4: What is the <datalist> element used for in HTML5?
- Providing a list of predefined options for an input field (Correct answer)
- Creating a dropdown select menu
- Defining a data table
- Listing form validation errors
Correct answer: Providing a list of predefined options for an input field
The <datalist> element contains a set of <option> elements representing autocomplete suggestions for an associated text input.
Question 5: Which attribute on an <input> element links it to a <datalist> for autocomplete suggestions?
- list (Correct answer)
- datalist
- for
- bind
Correct answer: list
The list attribute on an <input> references the id of a <datalist> element to provide autocomplete suggestions.
Question 6: What does the 'min' attribute specify on an HTML5 number input?
- The minimum acceptable value (Correct answer)
- The minimum number of characters
- The minimum field width
- The minimum label length
Correct answer: The minimum acceptable value
The min attribute sets the minimum value that an input of type number, range, or date will accept during validation.
Which HTML5 attribute allows you to validate an input field value against a regular expression?