Angular: Validation directive
http://angularjs.org/
HTML
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">Validation occurs inside ng-show directive<br>
Int 1: <input type="text" ng-model="int1"><br><br>
Int 2: <input ng-class="int2valid" type="text" ng-model="int2"><br>
<span ng-show="int1 > int2" style="color: red; display:none">Int 2 must be higher than Int 1</span>
<br>
<div ng-controller="MyCtrl">Validation unsing watcher<br>
Int 1: <input type="text" ng-model="int3"><br><br>
Int 2: <input ng-class="int2valid" type="text" ng-model="int4"><br>
<span ng-show="error" style="color: red; display:none">Int 2 must be higher than Int 1</span>
<br>
<br><br><br><br><br><br><br>
If Int 1 changes after the Int 2 field was validated the validation doesn't run until the values in Int 2 changes. Ie: Set Int 1 to 2, Int 2 to 3, and then change Int 1 to 5. Int 2 will still be marked as valid, even though it really isn't.
</div>
JavaScript
var myApp = angular.module('myApp', [])
function MyCtrl($scope) {
$scope.$watch('int3+int4', function () {
if($scope.int3 > $scope.int4) {
$scope.error = true;
}else {
$scope.error = false;
}
})
}