IT Specialist HTML5 Application Development INF-306 Question # 17 Topic 2 Discussion
INF-306 Exam Topic 2 Question 17 Discussion:
Question #: 17
Topic #: 2
You are creating a form that asks a user to enter their phone number. The form must be submitted only if the phone number field is not empty and matches the format 111-444-7777. Which markup should you use?
The correct markup is option D. The type= " tel " input type is appropriate for telephone-number entry, but it does not automatically validate a specific telephone-number format because phone formats vary internationally. MDN notes that tel inputs allow telephone entry but are not automatically validated to a particular format. Therefore, a pattern attribute is required to enforce the exact structure. The regular expression [0-9]{3}-[0-9] {3}-[0-9]{4} requires three digits, a hyphen, three digits, another hyphen, and four digits, matching the requested format such as 111-444-7777. MDN defines the pattern attribute as a regular expression the input value must match for constraint validation. The required attribute is also necessary because the field must not be empty; MDN states that required indicates the user must specify a value before the form can be submitted. Option A only limits length. Option B lacks hyphen validation and required. Option C hard-codes only specific digits. References/topics: HTML5 validation, tel, pattern, required, regular expressions.
==========
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit