javascript - AngularJS:ng-pattern 在输入字段中阻止非数字用户输入无效
问题描述
我试图防止输入字段中的非数字用户输入:
<input ng-model-options="{allowInvalid: false}" ng-pattern="/^[0-9]*$/"
class="cell large-3" ng-model="val1" />
不幸的是,我也可以在输入中输入字母。我怎样才能改变这种行为?
解决方案
我试图防止输入字段中的非数字用户输入
使用type="number"
:
<script src="//unpkg.com/angular/angular.js"></script>
<body ng-app>
<input type="number" ng-model="value" /><br>
value={{value}}
</body>
有关详细信息,请参阅
推荐阅读
- javascript - 我有错误'] 无效的配置对象。Webpack 已使用与 API 架构不匹配的配置对象进行初始化”
- mqtt - Nestjs - 远程服务中没有定义匹配的事件处理程序
- powershell-2.0 - 如何将自定义对象作为输入参数传递给自定义 PS cmdlet?
- javascript - 地图四处移动时如何使标记始终居中?
- c - 从要与 CURLOPT_URL 一起使用的文件中读取 url
- java - Jenkins 不支持在 Chrome 上运行的 selenium 上的 24 Clock
- c++ - 我有类“ my_string ”。我重载了运算符“==”,但它不适用于指针(my_string*)
- python - 如何将数据框转换为csv?
- go - 如何在 go 模块上版本和发布快照/未完成的工作?
- python - pymssql executemany 插入值非常慢