1
   <input type="text" ng-model="num1">
   <input type="text" ng-model="num2">

I want to compare numbers entered in above fields and generate error message if num1 < num2 using ng-form. We can do with JS but i want to keep validation simple. Can we implement in HTML tag using ng-form

user3335796
  • 1,227
  • 1
  • 17
  • 24
  • Possible duplicate of [Custom form validation directive to compare two fields](http://stackoverflow.com/questions/20982751/custom-form-validation-directive-to-compare-two-fields) – Vivek Athalye Feb 17 '17 at 11:33

1 Answers1

1

Try something like this:

<div ng-form="regForm">
   <span ng-show="num1>=num2">Num1 cannot be greater than num2</span>
   <input name="num1" type="text" ng-model="num1">
   <input name="num2" type="text" ng-model="num2">
</div>

JsFiddle: https://jsfiddle.net/sktajbir/6fmvsaf0/25/

Hope this will help you. Thanks.

Sk. Tajbir
  • 290
  • 2
  • 9
  • This code i have tried it before but it don't work. Because it validates only one digit of number. Example num1 = 33 and num2 = 200. Still message pop up. – user3335796 Jun 16 '16 at 05:46
  • but according to your logic it will show error if num1 < num2. So what is wrong here? – Sk. Tajbir Jun 16 '16 at 10:18
  • Actually problem is we are entering numbers in text fields. And try to compare. Its taking like a string rather than numbers. "<" symbol works correctly for numbers. So we have to use parseInt(num1) – user3335796 Jun 17 '16 at 06:59