简体   繁体   中英

AngularJS: ng-pattern to check for integer input

I'm stumped by the following problem. I have the following html input using AngularJS:

 <input class="form-control" type="number" name="widgetQuantity" id="widgetQuantity" ng-model="finalWidget.quantity" placeholder="Enter A Number" min="1" ng-pattern="/^\\d+$/" required/> <p ng-show="widgetForm.widgetQuantity.$error.min" class="help-block"> You gotta order at least one.</p> <p ng-show="widgetForm.widgetQuantity.$error.pattern" class="help-block"> No partial widgets, please.</p> 

The ng-pattern directive catches the negative symbol and decimals, but it's not catching "e" input into the form. Any thoughts? Thanks!

删除输入字段中的type="number"要求就解决了这个问题-显然HTML验证将覆盖有角度的错误。

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