I have created a form group like this:
import { checkPasswordStrength } from './validators';
@Component({
....
export class PasswordComponent {
...
this.userFormPassword = this.fb.group({
'password': ['', [checkPasswordStrength]]
});
In another TypeScript file, I have the checkPasswordStrength
method
export function checkPasswordStrength(c: FormControl) {
const SPECIAL_CHARACTERS_REGEX = /^\=\?$/;
return SPECIAL_CHARACTERS_REGEX.test(c.value) ? null : {
pwd: {
valid: false
}
};
}
The above code is functioning properly. However, I now need to pass a pattern attribute to the setPwd
method. So I attempted this:
this.userFormPassword = this.fb.group({
'password': ['', [checkPasswordStrength('**')]]
});
and the updated checkPasswordStrength
method is
export function checkPasswordStrength(c: FormControl, newPattern) {
But an error is being thrown. How can I successfully pass additional values to an external function?