angular - Custom validation for positive numbers -


i trying find information, if there built-in validators, check if input positive number?

i trying build following:

static nonzero(control:control) {     if (number(control.value) < 0) {         control.seterrors({nonzero: true})     } else {     control.seterrors(null)     } } 

however, didn't know how use in form builder:

this.form = _formbuilder.group({             field:['', validators.required]}) 

what doing wrong?

you can configure way leveraging validators.compose method:

this.form = _formbuilder.group({         field:['', validators.compose([                      validators.required, nonzero ])         ]}); 

this allows define 2 synchronous validators field.

edit

i implement validator way:

static nonzero(control:control):{ [key: string]: any; } {   if (number(control.value) < 0) {     return {nonzero: true};   } else {     return null;   } } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -