How to only allow the numbers 0-5 in <input> fields with AngularJS?

前端 未结 2 1221
无人及你
无人及你 2021-01-21 23:52

I have an input field like this:

HTML



        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-22 00:45

    You can add the following attribute to your input field.

    ng-pattern="/^[0-5]+$/" 
    

    And validate as such:

    function formCtrl($scope) {
    
    }
    
    
    The number must be between 0-5 No characters allowed The field is required

提交回复
热议问题