Programming in HTML5 with JavaScript and CSS3 — Question 21
You are developing a customer web form that includes the following HTML.
<input id="txtValue"/>
You need to change the HTML markup so that customers can enter only a valid three-letter country code.
Which HTML should you use?
Answer options
- A. <input id="txtValue" type="country"/>
- B. <input id="txtValue" type="text" required="xxx"/>
- C. <input id="txtVa!ue" type="text" pattern-" [A-Za-z] {3} "/>
- D. <input id="txtValuen type="code" pattern"="country"/>
Correct answer: C
Explanation
Option C is the correct choice because it uses the 'pattern' attribute with a regular expression that enforces exactly three alphabetic characters, which is suitable for country codes. Options A and D use incorrect types and patterns, while option B has a 'required' attribute that does not enforce the three-letter format.