4
<span editable-text="contact.phoneNumber" maxlength="5"  e-name="phoneNumber" e-form="contactForm" >
  {{ contact.phoneNumber || '' }}
</span>

I have used the directive inside a span and it is generating and inputbox on run time, when we click on a button to edit the Contact Number. I want to add a maximum length to this input box. Any suggestions?

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
Madhavi Jouhari
  • 2,282
  • 5
  • 25
  • 40
  • use limit: value, here value is the max length you want to provide. See this for help https://docs.angularjs.org/api/ng/filter/limitTo – Reena Apr 07 '15 at 09:33
  • What this will do is take a large number of input but display only within the limit. I need to take the input only in limited quantity. Its like entering your phone number and knowing that the constraint is for 10 digits only. – Madhavi Jouhari Apr 07 '15 at 09:44
  • Would you like to use regexp – Reena Apr 07 '15 at 09:51
  • Err.., it is more about limiting the input entries rather than validating them using regexp. – Madhavi Jouhari Apr 07 '15 at 09:59

2 Answers2

8

you can use

e-maxlength e-minlength

if you see the documentacion , on e attribute you have this:

Attributes defined with e-* prefix automatically transfered from original element to control.

Victor Morais
  • 96
  • 1
  • 3
  • what if you want it dynamic? like for credit cards, limit VISA to 16, but AMEX to 15 – Dave Mar 09 '16 at 18:22
0

Create a directive to limit the value:

app.directive("limitTo", [function() {
return {
    restrict: "A",
    link: function(scope, elem, attrs) {
        var limit = parseInt(attrs.limitTo);
        angular.element(elem).on("keydown", function() {
            if (this.value.length == limit) return false;
        });
    }
}   }]);

<input limit-to="4" type="number" class="form-control input-lg" ng-model="search.main" placeholder="enter first 4 digits: 09XX">

Hope this will be helping you

Reena
  • 1,109
  • 8
  • 16