简体   繁体   中英

Angular reactive forms using minlength only shows error when length is 0

Even though i have set the minlength to 5 it only gives me an error when the length is 0.

here is a plunker i have made that demonstrates that:

https://plnkr.co/edit/bJ9zeArGykATtRGh3Zev?p=preview

This is how i set the validation:

  formGroup.sensitivity = 
   this.formBuilder.control(this.reportModel.sensitivity, [Validators.required, 
   Validators.minLength(5)]);

For numbers, you should use Validators.min() instead of minLength() if you want to check for a number that must be minimum 5. minLength() is used for the number of characters in a text.

formGroup.sensitivity = 
   this.formBuilder.control(this.reportModel.sensitivity, [Validators.required, 
   Validators.min(5)]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM