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