IE11 Input type = Number

2020-05-06 07:56发布

问题:

I'm working with angular 4.3, I have an input field with input type number. I'm trying to restrict the user from entering any characters/letters. However, input type number is not fully supported and allows me to enter characters such as "ABCDEFG" within the input field. What would be the best approach to restrict letters?

<input type="number"/>

回答1:

If number doesn't work, I usually suggest to go for <input type="text" pattern="\d+"/>.

You can of course change your pattern to anything number-related (like (\d|[1-5]\d|60) to set min to 0 and max to 60)