lundi 24 juillet 2017

Multiple condition checking in Conditional ng-pattern in angular js

Markup

<input ... ng-pattern="handlePatternPassword">

Controller

$scope.handlePatternPassword = (function() {
  var regex = /^[A-Za-z0-9!@#$%^&*()_]{4,20}$/;
  return {
    test: function(value) {
      //if ($scope.isValid) {
      if ($scope.user.isLogged) {
        return (value.length > 0) ? regex.test(value) : true;
      } else {
        return regex.test(value);
      }
    }
  };
})();

I want to check different condition inside if in various forms. How to achieve that? Suppose in this case, $scope.isValid && $scope.user.isLogged both are true.

Aucun commentaire:

Enregistrer un commentaire