export function noWhitespaceValidator(control: FormControl) {
const isSpace = (control.value || '').match(/\s/g);
return isSpace ? {'whitespace': true} : null;
}
to use
password: ['', [Validators.required, noWhitespaceValidator]]
In template/html
<span *ngIf="newWpForm.get('password').hasError('whitespace')">
password cannot contain whitespace
</span>