Text input with number validation and transformation. Sets the number
validation
error if not a valid number.
<input type="number" ng-model="{string}" [name="{string}"] [min="{string}"] [max="{string}"] [required] [ng-minlength="{number}"] [ng-maxlength="{number}"] [ng-pattern="{string}"] [ng-change="{string}"]>
ng-model – {string} –
Assignable angular expression to data-bind to.
name(optional) – {string=} –
Property name of the form under which the control is published.
min(optional) – {string=} –
Sets the min
validation error key if the value entered is less then min
.
max(optional) – {string=} –
Sets the max
validation error key if the value entered is greater then min
.
required(optional) – {string=} –
Sets required
validation error key if the value is not entered.
ng-minlength(optional) – {number=} –
Sets minlength
validation error key if the value is shorter than
minlength.
ng-maxlength(optional) – {number=} –
Sets maxlength
validation error key if the value is longer than
maxlength.
ng-pattern(optional) – {string=} –
Sets pattern
validation error key if the value does not match the
RegExp pattern expression. Expected value is /regexp/
for inline patterns or regexp
for
patterns defined as scope expressions.
ng-change(optional) – {string=} –
Angular expression to be executed when input changes due to user interaction with the input element.
<script> function Ctrl($scope) { $scope.value = 12; } </script> <form name="myForm" ng-controller="Ctrl"> Number: <input type="number" name="input" ng-model="value" min="0" max="99" required> <span class="error" ng-show="myForm.list.$error.required"> Required!</span> <span class="error" ng-show="myForm.list.$error.number"> Not valid number!</span> <tt>value = {{value}}</tt><br/> <tt>myForm.input.$valid = {{myForm.input.$valid}}</tt><br/> <tt>myForm.input.$error = {{myForm.input.$error}}</tt><br/> <tt>myForm.$valid = {{myForm.$valid}}</tt><br/> <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/> </form>
it('should initialize to model', function() { expect(binding('value')).toEqual('12'); expect(binding('myForm.input.$valid')).toEqual('true'); }); it('should be invalid if empty', function() { input('value').enter(''); expect(binding('value')).toEqual(''); expect(binding('myForm.input.$valid')).toEqual('false'); }); it('should be invalid if over max', function() { input('value').enter('123'); expect(binding('value')).toEqual(''); expect(binding('myForm.input.$valid')).toEqual('false'); });