javascript - AngularJS:ng-pattern 检查整数输入

标签 javascript html angularjs validation

我被以下问题难住了。我使用 AngularJS 有以下 html 输入:

<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>

ng-pattern 指令捕获负号和小数,但它没有捕获表单中的“e”输入。有什么想法吗?谢谢!

最佳答案

删除输入字段中的 type="number" 要求解决了这个问题——显然 HTML 验证将覆盖来自 Angular 方面的错误。

关于javascript - AngularJS:ng-pattern 检查整数输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39970037/

相关文章:

javascript - 时区作为 cookies jquery PHP javascript

javascript - 使用ajax时如何解决未定义索引?

html - 设置边距 :auto on inline-flex container doesn't work as expected

javascript - 开发实时协作绘图系统

javascript - Highcharts - 数据不会加载到 Android WebView 上的图表中

javascript - IE无法管理 "global"变量?

javascript - 不能将自定义宽度与 Angular-Slick 一起使用

javascript - Angular js :ng-model is over writing the items in the ng-repeat

angularjs - AngularJS 嵌套数组中的 ng-repeat

javascript - 将解析后的 ng-repeat 数据传递到函数中