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..
<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
Post a Comment