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

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.