ValidatorOptional

noWhitespace

Reject a value with a space, tab or any other whitespace.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrInput } from 'ngwr/input';
import { WrValidators } from 'ngwr/validators';

@Component({ imports: [WrInput] })
export class MyComponent {}

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 }

API

NameDescriptionTypeDefault
signatureAdd it to a validators array.ValidatorFn—
error keyOn failure: { noWhitespace: true }. Empty value passes.{ noWhitespace: true }—

See also