Integer only validation for angularjs ng-pattern

时间:2017-12-18 06:31:45

标签: javascript angularjs regex ng-pattern

How to validate positive integer numbers using ng-pattern. Now i have this pattern ^[0-9]{1,7}(\.[0-9]+)?$/. But it allows decimal values. I need to disallow decimal values too

4 个答案:

答案 0 :(得分:1)

Very Simple! Just use ^\d+$ where, decimals won't be allowed

答案 1 :(得分:0)

try this in ng-pattern ^\-?\d+$ and not accept any -values

答案 2 :(得分:0)

Positive integers without leading zeros: ^[1-9]\d+$

答案 3 :(得分:0)

使用此表达式

ng-pattern="/^[0-9]*$/"

您可以在here

上查看正则表达式