Andris
-1
Q:

angular form validation whitespace

public noWhitespaceValidator(control: FormControl) {
    const isWhitespace = (control.value || '').trim().length === 0;
    const isValid = !isWhitespace;
    return isValid ? null : { 'whitespace': true };
}
0
new FormControl(field.fieldValue || '', [Validators.required, this.noWhitespaceValidator])
0
<div *ngIf="yourForm.hasError('whitespace')">Please enter valid data</div>
0

New to Communities?

Join the community