简体   繁体   English

ng-pattern仅适用于没有小数的数字

[英]ng-pattern for only number with no decimal

Need ng-pattern for restricting entry of decimal in input type number.I have used ng-pattern="/^[0-9]$/" to get the result but its not showing error on 1.0,2.0,3.0 etc. Example: 需要ng-pattern来限制输入类型数字中的小数输入。我已经使用ng-pattern =“ / ^ [0-9] $ /”来获得结果,但是在1.0、2.0、3.0等上未显示错误。 :

2.0 = fail
2 = pass
3.0=fail
3=pass

<div class="col-md-5 col-md-offset-7">

<input type="number"  min="0" class="form-control" id="equalizingFactor" 
 name="equalizingFactor" ng-model="flatVariable.equalizingFactor" 
 itle="Equalizing Factor" ng-maxlength="3" ng-pattern="/^[0-9]$/" 
 message="The field should contain only numbers with no decimal places"
 ng-readonly="flatVariable.pgmInd30"/>

</div>

Should only have numbers no decimals included. 应该只包含数字,不包括小数。

These should work fine: 这些应该可以正常工作:

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

ng-pattern="/^[0-9]+$/"  // 1 or more numbers

ng-pattern="/^\d*$/"     // 0 or more numbers

ng-pattern="/^\d+$/"     // 1 or more numbers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM