限制在AngularJS中输入的数字长度

时间:2016-05-11 11:24:48

标签: javascript jquery html angularjs angularjs-scope

<input class="span10" type="number" max="99999" ng-maxLength="5" placeholder="Enter Points" ng-change="myFunc($index)" ng-model="myVar">

如果值大于99999或5位,则只会将form.input.$valid的值更改为false。否则为true。但是,用户仍然可以输入任何长度的号码。 我只想限制他输入的数字,就像html的maxlength一样。

1 个答案:

答案 0 :(得分:2)

You will need to use the maxlength attribute as well. This post explains why.

Edit Seems Chrome is not honoring the maxlength when the input type is number, but it does for input type of text. Edge and IE do honor the maxlength when the input type is number. See this post for info on that.