I have following Angular 2 form:
I had the same problem where I wanted to validate a number field that contained the year, so I used Validators.maxLength(4)
to make sure someone does not accidently type 5 numbers for a year. Turns out when you set the input type to number:
then maxLength does not "work" anymore. Which actually makes sense if you think about it for half a second.
So I changed my date input to:
year: [null, [Validators.required, Validators.min(1990), Validators.max(2050)]],
Which is the right approach when working with a number field.