javascript - To allow input text accept only numbers -


below pluner have input text need make accept numbers.i have tried using normal angular js form validation event not firing .has face similar issue,request share thoughts..

link

  <input type="text" ng-model="valuesforoutputs[item.name][i]"                 ng-disabled="isdisabled(item.name, i)" ng-pattern="/^(\d)+$/"                                required   name="value"                                                placeholder="enter value">        <span class="error pop_up" ng-show="targetform.value.$error.pattern">please enter number</span> 

you can use onkeypress event of textfield:

 var allowonlynumbers=function(field){          if (!string.fromcharcode(event.keycode).match('[0-9.]') || (field.value.match('[.]') && string.fromcharcode(event.keycode) == '.'))             event.preventdefault();      };
 <input onkeypress='allowonlynumbers(this)' type="text" ng-model="valuesforoutputs[item.name][i]"                  ng-disabled="isdisabled(item.name, i)" ng-pattern="/^(\d)+$/"                                 required   name="value"                                                 placeholder="enter value">


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -