Validating length in AngularJS -


i have directive used text field , directive has validation below should show message when textfield length less 5 characters.

 attrs.$observe('usenumberregex', function( val ) {                   scope.usenumberregex = genericfieldutils.castboolean(val, false);                   if(scope.usenumberregex)                   {                     scope.regexp = /^\d+$/;                   }               }); 

and directive template url points html shown below

      <li ng-if="editable  && (cssclass == 'text_style_filter' || cssclass == 'drp_down_style')" style="float:left;width:42%" class="{{$parent.cssclass}}">        <input id="{{$parent.uniqueid}}" name="{{$parent.name}}" type="{{$parent.texttype}}"  class="field-control {{$parent.numcssclass}}" ng-pattern="$parent.regexp" autocomplete="off"  ng-required="mandatory" ng-maxlength="{{maxlength}}" maxlength="{{maxlength}}" ng-model="$parent.value" ng-disabled="disabled" ng-blur="$parent.onblur($parent.value)" ng-keyup="$parent.onkeyup($parent.value)" aria-label="{{$parent.arialabelinput}}" min="{{min}}" max="{{max}}" validate>             <div ng-if="$parent.formcontroller.submitcontroller.attempted">                 {{$parent.regexp}}               <span class="error-message" ng-repeat="error in errors" translate>{{error}}fdsfsdfsdf</span>             </div>           </li>  can please me going wrong in displaying message when length less 5 characters long. 

  1. you can use ng-minlength validate length of input.
  2. you use regex pattern validate same. instead of /^\d+$/ use /^\d{5,}$/

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -