0

So I have an input form in Angular here:

<input ng-model="sc.zip" class="form-control" maxlength="5" type="text" />

I don't want type="numbers" because the form needs to be a plain empty textbox. However, I only want the user to be able to type numbers. Either I need to detect when the input is not a digit, or be able to search through the box to find non-digits when submitting.

Either way, I need to validate that the form is digits only. Any help would be appreciated!

  • possible duplicate of [angular directive ignore non-numeric input](http://stackoverflow.com/questions/15554915/angular-directive-ignore-non-numeric-input) – Pankaj Parkar Jun 11 '15 at 15:36
  • possible duplicate of [angularjs: allows only numbers to be typed into a text box](http://stackoverflow.com/questions/16091218/angularjs-allows-only-numbers-to-be-typed-into-a-text-box) – Anik Islam Abhi Jun 11 '15 at 15:39

1 Answers1

1

use regex

  <input name="title" type="text" ng-model="sc.zip" ng-pattern="/^[0-9]*$/" required/>
vdj4y
  • 2,649
  • 2
  • 21
  • 31