Angular JS - How do you validate the number of digits in a number input

后端 未结 4 1649
执笔经年
执笔经年 2021-01-28 17:08

What we are looking to do is, have an input that only accepts 0 - 24 (for a time entry application).

These are the values the user should be able to enter into the inpu

4条回答
  •  遇见更好的自我
    2021-01-28 17:38

    Depends on the effect you want to achieve. You can do something like this:

    
    

    Which will prevent the user from entering any more than 2 characters. If the characters are anything but a number, it will set the field class to ng-invalid-pattern.

    If you don't want to prevent the user from entering two characters and just want to show a validation message if they enter three or more, just remove the maxlength.

提交回复
热议问题