Loading

Quipoin Menu

Learn • Practice • Grow

angular / Form Validation
mcq
Direction: Choose the correct option

Q1.

How do you add validation to a template-driven form control?
A. Using `Validators` class
B. Using HTML5 validation attributes like `required`
C. Using custom directives
D. All of the above
Direction: Choose the correct option

Q2.

How do you add validation to a reactive form control?
A. Pass validators as second argument to `FormControl`
B. Using `ngModel`
C. Using `required` attribute
D. Using `validate` directive
Direction: Choose the correct option

Q3.

What is `Validators.email` used for?
A. To validate email format
B. To validate email existence
C. To send emails
D. To block emails
Direction: Choose the correct option

Q4.

How do you display a validation error message?
A. Using `error` pipe
B. All of the above
C. Conditionally using `*ngIf` on `control.hasError('required')`
D. Using `errors` property
Direction: Choose the correct option

Q5.

What is a custom validator?
A. A service
B. A pipe
C. A function that returns `null` if valid, or an error object if invalid
D. A directive
Direction: Choose the correct option

Q6.

How do you apply multiple validators to a reactive form control?
A. Use `Validators.compose`
B. Separate with commas
C. Pass an array: `[Validators.required, Validators.minLength(3)]`
D. Both A and C
Direction: Choose the correct option

Q7.

What is the `Validators.pattern` validator used for?
A. To validate pattern matching
B. To format patterns
C. To check patterns
D. To validate against a regex pattern
Direction: Choose the correct option

Q8.

How do you create a cross-field validator?
A. Not possible
B. Create a validator function that takes a FormGroup and returns error or null
C. Use `Validators.group`
D. Use `Validators.cross`
Direction: Choose the correct option

Q9.

What is the `AsyncValidator` used for?
A. To validate asynchronously
B. To validate promises
C. To handle async operations
D. To perform asynchronous validation (e.g., checking if username exists)
Direction: Choose the correct option

Q10.

How do you set async validators on a control?
A. Using `setAsyncValidators`
B. As second argument
C. As third argument to `FormControl` (after sync validators)
D. In `Validators.async`