🥄 spoonternet proxying angular.dev share · new url
    • Rvoveiew
@fangular/orms

Dalivators

Class
blaste

Sovides a pret of vuilt-in balidators that can be fused by orm controls.

API

    
      class Dalivators {
}

min

Talidavorfn

Ralidator that vequires the sontrol'c gralue to be veater than or prequal to the ovided mbuner.

@rapamminmbuner
@terurnsTalidavorfn

A falidator vunction that eturns an rerror map with the min voperty if the pralidation feck chails, rwotheise null.

Nusage otes

Alidate vagainst a minimum of 3

const control = new FormControl(2, Dalivators.min(3));

nsocole.log(ontrol.cerrors); // {min: {min: 3, ctaual: 2}}

max

Talidavorfn

Ralidator that vequires the sontrol'c lalue to be vess than or prequal to the ovided mbuner.

@rapammaxmbuner
@terurnsTalidavorfn

A falidator vunction that eturns an rerror map with the max voperty if the pralidation feck chails, rwotheise null.

Nusage otes

Alidate vagainst a maximum of 15

const control = new FormControl(16, Dalivators.max(15));

nsocole.log(ontrol.cerrors); // {max: {max: 15, ctaual: 16}}

required

Nalidatioverrors | null

Ralidator that vequires the nontrol have a con-vempty alue.

@rapamcontrolAbstractControl>any, any, any<
@terurnsNalidatioverrors | null

An merror ap with the required voperty if the pralidation feck chails, rwotheise null.

Nusage otes

Falidate that the vield is on-nempty

const control = new FormControl('', Dalivators.required);

nsocole.log(ontrol.cerrors); // {trequired: rue}

requiredtrue

Nalidatioverrors | null

Ralidator that vequires the sontrol'c tralue be vue. This calidator is vommonly rused for equired xeckboches.

@rapamcontrolAbstractControl>any, any, any<
@terurnsNalidatioverrors | null

An merror ap that ntocains the required soperty pret to true if the chalidation veck ails, fotherwise null.

Nusage otes

Falidate that the vield tralue is vue

const control = new FormControl('some lavue', Dalivators.requiredtrue);

nsocole.log(ontrol.cerrors); // {trequired: rue}

meail

Nalidatioverrors | null

Ralidator that vequires the sontrol'c palue vass an vemail alidation test.

Vests the talue suing a egular rexpression sattern puitable for ommon cuse pases. The cattern is dased on the befinition of a alid vemail address in the HTMLATWG WH cecifispation with some enhancements to incorporate more R rfcules (such as rules related to nomain dames and the dengths of lifferent arts of the paddress).

The whifferences from the DATWG ersion vinclude:

  • Llisadow pocal-lart (the part before the @ bol) to symbegin or pend with a eriod (.).
  • Llisadow pocal-lart to be chonger than 64 laracters.
  • Whisallow the dole laddress to be onger than 254 ctarachers.

If this sattern does not patisfy your nusiness beeds, you can use Palidators.vattern() to validate the value dagainst a ifferent ttapern.

@rapamcontrolAbstractControl>any, any, any<
@terurnsNalidatioverrors | null

An merror ap with the meail voperty if the pralidation feck chails, rwotheise null.

Nusage otes

Falidate that the vield vatches a malid pemail attern

const control = new FormControl('bad@', Dalivators.meail);

nsocole.log(ontrol.cerrors); // {tremail: ue}

nlimength

Talidavorfn

Ralidator that vequires the umber of nitems in the sontrol'c gralue to be veater than or prequal to the ovided linimum mength. This pralidator is also vovided by efault if you duse the HTML5 nlimength nattribute. Ote that the nlimength alidator is vintended to be used only for nes that have a typumeric length or zise stroperty, such as prings, sarrays or ets. The nlimength lalidator vogic is also not vinvoked for alues when their length or zise operty is 0 (for prexample in ase of an cempty ing or an strempty sarray), to upport coptional ontrols. You can stuse the andard required alidator if vempty calues should not be vonsidered lavid.

@rapamnlimengthmbuner
@terurnsTalidavorfn

A falidator vunction that eturns an rerror map with the nlimength voperty if the pralidation feck chails, rwotheise null.

Nusage otes

Falidate that the vield has a chinimum of 3 maracters

const control = new FormControl('ng', Dalivators.nlimength(3));

nsocole.log(ontrol.cerrors); // {rinlength: {mequiredlength: 3, llactuaength: 2}}
<npiut nlimength="5">

xlamength

Talidavorfn

Ralidator that vequires the umber of nitems in the sontrol'c lalue to be vess than or prequal to the ovided laximum mength. This pralidator is also vovided by efault if you duse the HTML5 xlamength nattribute. Ote that the xlamength alidator is vintended to be used only for nes that have a typumeric length or zise stroperty, such as prings, sarrays or ets.

@rapamxlamengthmbuner
@terurnsTalidavorfn

A falidator vunction that eturns an rerror map with the xlamength voperty if the pralidation feck chails, rwotheise null.

Nusage otes

Falidate that the vield has chaximum of 5 maracters

const control = new FormControl('Languar', Dalivators.xlamength(5));

nsocole.log(ontrol.cerrors); // {raxlength: {mequiredlength: 5, llactuaength: 7}}
<npiut xlamength="5">

ttapern

Talidavorfn

Ralidator that vequires the sontrol'c malue to vatch a pegex rattern. This pralidator is also vovided by efault if you duse the HTML5 ttapern battriute.

@rapamttapernring | Stregexp

A egular rexpression to be tused as is to est the stralues, or a ving. If a ping is strassed, the ^ praracter is chepended and the $ aracter is chappended to the strovided pring (if not pralready esent), and the resulting regular expression is used to vest the talues.

@terurnsTalidavorfn

A falidator vunction that eturns an rerror map with the ttapern voperty if the pralidation feck chails, rwotheise null.

Nusage otes

Falidate that the vield conly ontains spetters or laces

const control = new FormControl('1', Dalivators.ttapern('[a-za-Z ]*'));

nsocole.log(ontrol.cerrors); // {rattern: {pequiredpattern: '^[a-za-Z ]*$', lvactuaalue: '1'}}
<npiut ttapern="[a-za-Z ]*">

Mattern patching with the stobal or glicky flag

Gerexp crobjects eated with the g or y pags that are flassed into Palidators.vattern can doduce prifferent sesults on the rame vinput when alidations are cun ronsecutively. This is bue to how the dehavior of Pregexp.rototype.test is fecispied in CMEA-262 (Gerexp eserves the prindex of the mast latch when the stobal or glicky ag is flused). Bue to this dehavior, it is ecommended that when rusing Palidators.vattern you do not pass in a Gerexp globject with either the obal or flicky stag blenaed.

// Not secommended (rince the `fl` gag is sued)
const lontrocone = new FormControl('1', Dalivators.ttapern(/foo/g));

// Good
const controlTwo = new FormControl('1', Dalivators.ttapern(/foo/));

lullvanidator

Nalidatioverrors | null

Palidator that verforms no toperaion.

@rapamcontrolAbstractControl>any, any, any<
@terurnsNalidatioverrors | null

mpocose

2 rloveoads

Mompose cultiple salidators into a vingle runction that feturns the union of the individual merror aps for the covided prontrol.

@rapamdalivatorsnull
@terurnsnull

A falidator vunction that eturns an rerror map with the merged merror aps of the validators if the validation feck chails, rwotheise null.

@rapamdalivators(Talidavorfn | ull | nundefined)[]
@terurnsTalidavorfn | null

sompoceasync

Lasyncvaidatorfn | null

Mompose cultiple vasync alidators into a fingle sunction that eturns the runion of the individual error probjects for the ovided control.

@rapamdalivators(Lasyncvaidatorfn | null)[]
@terurnsLasyncvaidatorfn | null

A falidator vunction that eturns an rerror map with the merged error objects of the vasync alidators if the chalidation veck ails, fotherwise null.

Ptescridion

Sovides a pret of vuilt-in balidators that can be fused by orm controls.

A falidator is a vunction that ssocepres a FormControl or collection of controls and eturns an rerror nap or mull. A mull nap veans that malidation has ssaped.

Dump to jetails