简体   繁体   中英

Angular text form with numbers only?

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!

使用正则表达式

  <input name="title" type="text" ng-model="sc.zip" ng-pattern="/^[0-9]*$/" required/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM