Join the discussion
Question 2/22
Review the following markup segment:
< form action= " process.js " method= " get " >
< label for= " secretcode " > Secret Code < /label >
< input type= " text " name= " secretcode "
pattern= " [a-zA-Z]{4}-[0-9] {2}-[0-9]{4}-[a-zA-Z] {4} "
placeholder= " secretcode " >
< input type= " submit " value= " Submit " >
< /form >
Which entry will validate successfully according to the required pattern?
< form action= " process.js " method= " get " >
< label for= " secretcode " > Secret Code < /label >
< input type= " text " name= " secretcode "
pattern= " [a-zA-Z]{4}-[0-9] {2}-[0-9]{4}-[a-zA-Z] {4} "
placeholder= " secretcode " >
< input type= " submit " value= " Submit " >
< /form >
Which entry will validate successfully according to the required pattern?
Correct Answer: D
The correct answer is D because the pattern attribute requires the exact structure defined by the regular expression [a-zA-Z]{4}-[0-9] {2}-[0-9]{4}-[a-zA-Z] {4}. The first group, [a-zA-Z]{4}, requires exactly four alphabetic characters. The second group, [0-9] {2}, requires exactly two numeric digits. The third group, [0-9]
{4}, requires exactly four numeric digits. The final group, [a-zA-Z] {4}, requires exactly four alphabetic characters. Hyphens must appear between each group. Option D, kukX-34-4938-WJDF, satisfies every part:
kukX is four letters, 34 is two digits, 4938 is four digits, and WJDF is four letters. Option A fails because Uhj6 contains a digit in the final letter-only group. Option B fails because y7Ts contains a digit in the first group and A3 is not two digits. Option C fails because 23h contains a letter and breaks the two-digit group.
References/topics: HTML5 input validation, pattern attribute, regular expressions, form constraint validation.
{4}, requires exactly four numeric digits. The final group, [a-zA-Z] {4}, requires exactly four alphabetic characters. Hyphens must appear between each group. Option D, kukX-34-4938-WJDF, satisfies every part:
kukX is four letters, 34 is two digits, 4938 is four digits, and WJDF is four letters. Option A fails because Uhj6 contains a digit in the final letter-only group. Option B fails because y7Ts contains a digit in the first group and A3 is not two digits. Option C fails because 23h contains a letter and breaks the two-digit group.
References/topics: HTML5 input validation, pattern attribute, regular expressions, form constraint validation.
Add Comments
- Other Question (22q)
- Q1. You need to display the following user interface: A text input field that displays a selec...
- Q2. Review the following markup segment: < form action= " process.js " method= " get " >...
- Q3. You need to define a grid that meets the following requirements: * Explicitly sets the wid...
- Q4. You are creating a script that reads a JSON menu file and displays the Entree, Price, and ...
- Q5. You are creating a form that requires the category to be entered as a two- or three-letter...
- Q6. You have created custom error messages for a form. When a user attempts to submit the form...
- Q7. The following form is missing validation attributes: < form > < div class= " cont...
- Q8. You write the following markup to create a page. Line numbers are included for reference o...
- Q9. Which CSS property defines the sides of an element where other floating elements are not a...
- Q10. You define the following layout: < !DOCTYPE html > < html > < head > <...
- Q11. The following output has more text than will fit in the element. (Exhibit) You need to app...
- Q12. The logo shown is displayed on a web page as an SVG. Note: The coordinate values are label...
- Q13. Review the markup segment. Which entry will validate successfully according to the require...
- Q14. Which two statements correctly describe media queries? Choose 2....
- Q15. The following code adds items to the groceries array from the other arrays. Line numbers a...
- Q16. You create an interface for a touch-enabled application. You discover that some of the inp...
- Q17. You need to create the layout shown, which defines five content areas: * Logo and page tit...
- Q18. Match each property to its corresponding value for creating the CSS flexible box layout. M...
- Q19. Which markup segment creates an SVG ellipse?
- Q20. A local photographer asks you to add filters as shown to the images in their photo gallery...
- Q21. You need to ensure that the value of an input element is a valid 10-digit phone number wit...
- Q22. You define the Pet class as follows: class Pet { constructor(name, breed) { this.name = na...
