admin管理员组文章数量:1355554
I have the following input
<input type="text" name="area" class="form-control" ng-pattern="onlyNumbers" ng-model="myForm.area" required>
and the ng-pattern only allows the input to have numbers.
$scope.onlyNumbers = /^\d+$/;
I also would like some way to tell the input that the number must be greater than 0. Meaning that the user must not input something like 023, it must be 23.
I have the following input
<input type="text" name="area" class="form-control" ng-pattern="onlyNumbers" ng-model="myForm.area" required>
and the ng-pattern only allows the input to have numbers.
$scope.onlyNumbers = /^\d+$/;
I also would like some way to tell the input that the number must be greater than 0. Meaning that the user must not input something like 023, it must be 23.
Share Improve this question edited Jul 4, 2014 at 17:03 Beed 4603 silver badges10 bronze badges asked Jul 4, 2014 at 16:47 Sergio Robledo ArangoSergio Robledo Arango 1771 gold badge5 silver badges11 bronze badges3 Answers
Reset to default 6You can just change the regex:
$scope.onlyNumbers = /^[1-9][0-9]*$/;
Option allowing floats with ,
or .
separators.
$scope.onlyNumbers = /^(0*[1-9][0-9]*([\.\,][0-9]+)?|0+[\.\,][0-9]*[1-9][0-9]*)$/;
This will allow for any number above zero (eg, 0.0002).
$scope.onlyNumbers = /^0*[1-9][0-9]*(\.[0-9]+)?|0+\.[0-9]*[1-9][0-9]*$/
本文标签: javascriptAngular JS directive for number greater than 0Stack Overflow
版权声明:本文标题:javascript - Angular JS directive for number greater than 0 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743977799a2570946.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论