Validator

noWhitespace

Reject any space, tab, or other whitespace inside the value. Empty values pass.

Live demo

errors: null

Usage

import { FormControl } from '@angular/forms';
import { WrValidators } from 'ngwr/validators';

const username = new FormControl('', [WrValidators.noWhitespace]);

username.setValue('foo bar');
username.errors; // { noWhitespace: true }

Why ngwr provides this

Angular's required happily accepts a string of spaces. This rejects whitespace anywhere in the value without you trimming the model on every keystroke.

API

NameDescriptionTypeDefault
signatureStatic — drop into a validators array.ValidatorFn
error keyOn failure: { noWhitespace: true }. Empty value passes.{ noWhitespace: true }

See also