Bird
0
0

You want to create a form input that requires exactly 5 uppercase letters using Angular template attributes. Which is the correct input element?

hard📝 component behavior Q8 of 15
Angular - Template-Driven Forms
You want to create a form input that requires exactly 5 uppercase letters using Angular template attributes. Which is the correct input element?
A<input name="code" ngModel required pattern="[A-Z]{5}">
B<input name="code" ngModel required pattern="^[A-Z]{5}$">
C<input name="code" ngModel required minlength="5" maxlength="5">
D<input name="code" ngModel required pattern="^[a-z]{5}$">
Step-by-Step Solution
Solution:
  1. Step 1: Define exact length and case with pattern

    The pattern must match exactly 5 uppercase letters, so use anchors ^ and $ with [A-Z]{5}.
  2. Step 2: Compare options for correctness

    uses correct anchors and uppercase range. lacks anchors, allowing partial matches. only checks length, not uppercase. uses lowercase letters.
  3. Final Answer:

    <input name="code" ngModel required pattern="^[A-Z]{5}$"> -> Option B
  4. Quick Check:

    Use ^[A-Z]{5}$ for exact 5 uppercase letters [OK]
Quick Trick: Use ^ and $ anchors to enforce exact pattern length [OK]
Common Mistakes:
MISTAKES
  • Omitting anchors in regex pattern
  • Using minlength/maxlength without pattern
  • Confusing uppercase and lowercase ranges

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes