AngularJS:ng-pattern has no effect preventin non numeric userinput in input-field

131 views Asked by At

I'm trying to prevent non numeric userinput in an inputfield:

 <input ng-model-options="{allowInvalid: false}" ng-pattern="/^[0-9]*$/"
        class="cell large-3"  ng-model="val1" />

Unfortunatelly i can input also letters in the input. How I can change this behaviour?

1

There are 1 answers

0
georgeawg On

I'm trying to prevent non numeric userinput in an inputfield

Use type="number":

<script src="//unpkg.com/angular/angular.js"></script>
<body ng-app>
    <input type="number" ng-model="value" /><br>
    value={{value}}
</body>

For more information, see