Bird
0
0

Identify the error in this Angular form control validator setup:

medium📝 Debug Q14 of 15
Angular - Reactive Forms
Identify the error in this Angular form control validator setup:
new FormControl('', [Validators.required, Validators.pattern('[a-zA-Z]+'))
AMissing closing parenthesis for Validators.pattern
BPattern string should be a RegExp object, not a string
CValidators.required cannot be combined with Validators.pattern
DNo error, this setup is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of Validators.pattern

    The pattern validator call has an opening parenthesis but is missing the closing parenthesis at the end.
  2. Step 2: Verify other options

    Pattern can accept a string, and required can be combined with pattern, so options B and C are incorrect.
  3. Final Answer:

    Missing closing parenthesis for Validators.pattern -> Option A
  4. Quick Check:

    Unmatched parentheses cause syntax error [OK]
Quick Trick: Count parentheses carefully in validator calls [OK]
Common Mistakes:
MISTAKES
  • Forgetting closing parenthesis
  • Thinking pattern needs RegExp object only
  • Believing required and pattern can't combine

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes