validation with angular material code example
Example: form validation in angular material example
setPhoneValidation() { const phoneControl = this.registerForm.get("phone"); phoneControl.setValidators([Validators.pattern("^[0-9]*$"), Validators.required,]);this.registerForm.get("role").valueChanges.subscribe((role) => { if (role == "jobSeeker") { phoneControl.setValidators([Validators.pattern("^[0-9]*$"), Validators.required,]);} else if (role == "employee") { phoneControl.setValidators([Validators.pattern("^[0-9]*$")]); } phoneControl.updateValueAndValidity();});}