0

i have to validate the text box which shows the error message when user enters 4 digit as 9999.so i have used the ng-pattern method to show error message but ng-pattern does n't allow to update the object.my code is given below:

  <md-input-container class="" style="margin:5px 0px; margin-right:15px;">

      <input type="password" name="numCode" ng-model="datas.part[1].Value" ng-value="datas.part[1].Value" maxlength="4" ng-pattern="/(?!9{4})\d{4}/" ng-keydown="vm.testCode(datas.part[1].Value)" class="ng-pristine ng-valid md-input ng-touched"  aria-invalid="false" style="" autocomplete="off" required>
      <div ng-messages="vm.formName.numCode.$error" class="allign-padding-bottom" role="alert">
           <div ng-message-exp="['minlength','maxlength','pattern']">
                        {{::'testcode'|translate}}
            </div>
       </div>
    </md-input-container>

 vm.testCode= function (val) {
            console.info("sdf",val);
            vm.showConfirmUserCode = true;
            ///vm.isDeviceEnabled = false;
        }

In ng-keydown method the model did n't update.it shows undefined in vm.formName.numCode.$viewvalue.kindly help me to sort out this problem & check my ng-pattern.if i remove my ng-pattern means i have the updated model

7
  • can you also add the relative code for vm.testCode() method and any related methods inside of vm.testCode() Commented Oct 16, 2017 at 16:57
  • only thing that appears off to me is Value might need have a lower case v Commented Oct 16, 2017 at 16:59
  • i have updated my code and my problem is with ng-pattern because if i removed it means model gets updated Commented Oct 16, 2017 at 17:08
  • @Sathish, what is the purpose of the regex? Should it alert when the user enters 4 consecutive 9's? Commented Oct 16, 2017 at 17:14
  • @VijayMenon the regex purpose is if user enter four 9's means it should shows the error message but it may 1234,5555...etc Commented Oct 16, 2017 at 17:16

1 Answer 1

0

Please check this plunker: http://plnkr.co/edit/g0wsbFnfi6TEW76orxIJ?p=preview

 <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>

    <form name="form1" novalidate>

  <input type="password" name="numCode" ng-model="inputText" ng-value="inputText" ng-pattern="/(?!9{4})\d{4}/" ng-maxlength="4" ng-keydown="testCode(inputText)" aria-invalid="false" style="" autocomplete="off" required>
  <div ng-messages="form1.numCode.$error" role="alert">
           <div ng-message="pattern">pattern error</div>
            <div ng-message="maxlength">maxlength error</div>
             <div ng-message="required">required error</div>
   </div>
</form>
  </body>

Have you referenced angular-messages as a seperate library? The ng-keydown works if its a valid text and the error messages are shown correctly.

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.