0

Hi i would like to setValidity of input using an expression, but not a regEx, something like this

<input ng-model="number" required ng-valid="number / 2 > 14">

Is it possible i have complex function and i don't know how to convert it into regEx so i would like to use something like this. I try to use this library: https://github.com/turinggroup/angular-validator but it doesn't work at all :/

1

1 Answer 1

0

You may try something like this:

<div ng-app="myApp">
    <div ng-controller="myController">
        <input ng-model="number" required ng-keyup="checkValid(number)">
        <span style="color:red" ng-if="!isValid">Not a valid number</span>
    </div>
</div>

And create a function like following:

(function(){

    var myApp = angular.module('myApp', []);

    myApp.controller('myController', function($scope, $timeout){
        $scope.isValid = true;

      $scope.checkValid = function(value){
        if(value){
            if(value/2>14){
            $scope.isValid = true;
          }else{
            $scope.isValid = false;
          }
        }
      }  


    });

})();
Sign up to request clarification or add additional context in comments.

Comments

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.