3

When an user entering a value, system should check whether this value is within the range of Minimum and Maximum defined for this field. also, need check for number of decimal points allowed.

<input  ng-model='data.value1' >
<input  ng-model='data.value2' >
<input  ng-model='data.value3' >
<input  ng-model='data.value4' >
2
  • Use regular expression for this. Commented Dec 15, 2014 at 14:09
  • You can also check value using javaScript. Commented Dec 15, 2014 at 14:09

2 Answers 2

5

you can add type="number". and for angularJS

<input type="number"
       ng-model=""
       [name=""]
       [min=""]
       [max=""]
       [required=""]
       [ng-required=""]
       [ng-minlength=""]
       [ng-maxlength=""]
       [pattern=""]
       [ng-pattern=""]
       [ng-change=""]>

Follow the link for more clarification AngularJs Documentation

Sign up to request clarification or add additional context in comments.

1 Comment

If it is type="number", you could use ng-max and ng-min
2

Extending My comment:

 var range = 'your range';
 var checkRange = function () {
    var value = data.value;
    if(value <=range) {
    //your code;
    } else {
    //your code;
    }
}

Update:

$scope.data.value = 500;
$scope.$watch('data.value', function (oldVal,newVal) {
     if(newVal > 1000 ) {
      $scope.data.value = 500;
}

})

9 Comments

Consider if I have 5 textbox controls and for all I need to do this same validation. And, if user entered a value which is not fall in the range then, I should reset the entered value to its old value.
You should use regular expression for this. I don't know what is your range, but there are many ways to do this.
Help me on one thing... I want to reset to old value if the given value is invalid. if my range is 10-1000 and my current/default value is 500. if user enters 1200, then i should reset back to 500.
Ok.. I am writing a solution for this.
No. just use as it is in your controller. You don't need to pass any value to oldVal and newVal.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.