Regex with ng-if

10,719

On your view:

ng-if="isValid()"

in your controller:

$scope.isValid = function(){
   return MyTest.Item.MyPassword == MyTest.Item.ConfirmPassword 
          && yourRegexp.test(MyTest.Item.MyPassword);
}
Share:
10,719

Related videos on Youtube

Sampath
Author by

Sampath

Angular, Ionic, Firestore, Typescript, PrimeNG Connect with ME : Twitter

Updated on June 04, 2022

Comments

  • Sampath
    Sampath almost 2 years
      <div class="row" ng-if="MyTest.Item.MyPassword != MyTest.Item.ConfirmPassword">
           <div class="col-md-12">
          <p class="red-color"> Password must be between 4 and 8 digits long and include at least one numeric digit And Passwords must match! </p>
            </div>
     </div>
    

    I need to show the above message when "Mypassword != ConfirmPassword" and the regex '/^(?=.*\d).{4,8}$/' is not fulfilled with the password field.How can I use regex with ng-if ? Any help would be highly appreciated.

  • Sampath
    Sampath over 9 years
    How can we call a function within a ng-if ? it should be a boolean value no ?
  • Artyom Pranovich
    Artyom Pranovich over 9 years
    @Sampath, yes. But my isValid() function returns boolean value too. See the following example: jsfiddle.net/JuS7W
  • caden311
    caden311 over 5 years
    This isn't great practice. That function isValid will be called infinitely. Thus performance suffers.