I have tried using below code for which the textarea accepts numbers greater than 0 and less than 5, everything is working fine but when comes to decimal it unable to validate. below is my code
<body ng-controller="MainCtrl">
<form name="myform">
<input type="number" min="0" name="minmax" ng-model="number" required="required" maxlength="10" numbers-only/>
<span ng-show="myform.$error.numbersOnly">Enter the numbers only between 0 to 5 </span>
</form>
</body>
and here is controller
var app = angular.module('plunker', []);
app.directive('numbersOnly', function(){
return {
require: 'ngModel',
link: function(scope, element, attrs, modelCtrl) {
modelCtrl.$parsers.push(function (inputValue) {
if(parseInt(inputValue) <= 5 && parseInt(inputValue) > 0){
modelCtrl.$setValidity('numbersOnly', true);
return inputValue;
} else {
modelCtrl.$setValidity('numbersOnly', false);
return modelCtrl.$modelValue;
}
});
}
};
});
function MyCtrl($scope) {
$scope.number = ''
}
and here is my working plunker http://plnkr.co/edit/rOShiJYCZrXcgMdr951i?p=preview