inputField: new FormControl('', [Validators.required])
when the user enters '0' in the field, the error required is applied on the control.
Zero should be considered as a value.
By default, If you enter anything into formControl element angular form will treat it as truthy value -
inputField: new FormControl(0, [Validators.required]) //valid
inputField: new FormControl('', [Validators.required]) //invalid
But yes, you can add some regex pattern as well to check value match for 0
only, for example -
inputField = new FormControl(0, [Validators.required, Validators.pattern(/^[1-9]*$/)])
you're mistaken somewhere.
stackblitz shows 0 meets a required validator: https://stackblitz.com/edit/angular-bmqvtq?file=src/app/app.component.ts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With