Which attribute on form controls constrains the acceptable input to a regular expression without JavaScript?

Prepare for the uCertify CIW Advanced HTML5 and CSS3 Specialist Exam. Dive into essential topics with flashcards and multiple-choice questions. Enhance your understanding with hints and explanations for each question. Pass your exam confidently!

Multiple Choice

Which attribute on form controls constrains the acceptable input to a regular expression without JavaScript?

Explanation:
Pattern is the HTML5 attribute that lets you constrain what users can enter by a regular expression without any JavaScript. When a value is entered, the browser checks it against this regex as part of its built-in form validation. If the value doesn’t match, the form can’t be submitted until it’s corrected, often with a helpful message shown from the title attribute or the browser’s default message. This is how you enforce formats like alphanumeric strings, specific lengths, or particular character sets without writing extra code. For example, an input like <input type="text" pattern="[A-Za-z0-9_-]{3,16}" title="3–16 characters; letters, numbers, underscores, or hyphens"> will only allow values that are 3 to 16 characters long using the specified characters. The other terms aren’t actual HTML attributes, so they wouldn’t enforce any constraint. Regex isn’t an attribute name, and constraint or validate aren’t standard HTML attributes.

Pattern is the HTML5 attribute that lets you constrain what users can enter by a regular expression without any JavaScript. When a value is entered, the browser checks it against this regex as part of its built-in form validation. If the value doesn’t match, the form can’t be submitted until it’s corrected, often with a helpful message shown from the title attribute or the browser’s default message. This is how you enforce formats like alphanumeric strings, specific lengths, or particular character sets without writing extra code.

For example, an input like will only allow values that are 3 to 16 characters long using the specified characters.

The other terms aren’t actual HTML attributes, so they wouldn’t enforce any constraint. Regex isn’t an attribute name, and constraint or validate aren’t standard HTML attributes.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy