如何在angularjs的文本框中只允许数字?

吉塔·贾纳(Geetha Janar)

嗨,我是Angle JS的新手吗?用户输入十进制值或显示角度js错误的字符串时,如何仅在texbox中允许数字?

 <div class="col-md-6 col-sm-6"> 
                                                        <label class="col-md-5 col-sm-5 pad-top5 pad-lft-no">Min <span class="error">*</span></label>
                                                        <input positive  type="number" class="col-md-7 col-sm-7 cls_input_inherit numberinput" min="0" ng-maxlength="3" id="age_min" name="age_min" ng-model="attributes.age_min"  required/>
                                                        <label for="age_min" ng-show="submittab2 && attributesForm2.age_min.$error.required" class="error">{{formValidation.required}}</label>                                                           
                                                        <label for="age_min" ng-show="submittab2 && !attributesForm2.age_min.$error.positive &&  attributesForm2.age_min.$error.maxlength" class="error"> {{formValidation.monthMaxChar}} </label>
                                                        <label for="age_min" ng-show="submittab2 && !attributesForm2.age_min.$error.positive && !attributesForm2.age_min.$error.maxlength && attributesForm2.age_min.$error.min" class="error">{{formValidation.minMax}}</label>
                                                        <label for="age_min" ng-show="submittab2 && !attributesForm2.age_min.$error.positive && !attributesForm2.age_min.$error.maxlength && attributesForm2.age_min.$error.number" class="error">{{formValidation.errorNumber}}</label>
                                                        <label for="age_min" ng-show="submittab2 && attributesForm2.age_min.$error.positive" class="error">{{formValidation.minpositive}}</label>
                                                    </div>

是否尝试上述代码,但输入十进制值时未显示错误?如何解决?

泽山古尔班

您需要在输入字段中添加ng-pattern =“ / ^(\ d)+ $ /”。

 <div class="col-md-6 col-sm-6"> 
 <label class="col-md-5 col-sm-5 pad-top5 pad-lft-no">Min <span class="error">*</span></label>
                                                    <input positive  type="number" class="col-md-7 col-sm-7 cls_input_inherit numberinput" min="0" ng-maxlength="3" id="age_min" name="age_min" ng-model="attributes.age_min" ng-pattern="/^(\d)+$/" required/>
                                                    <label for="age_min" ng-show="submittab2 && attributesForm2.age_min.$error.required && attributesForm2.age_min.$touched && attributesForm2.age_min.$invalid"  class="error">{{formValidation.required}}</label>                                                           
                                                    <label for="age_min" ng-show="submittab2 && !attributesForm2.age_min.$error.positive &&  attributesForm2.age_min.$error.maxlength" class="error"> {{formValidation.monthMaxChar}} </label>
                                                    <label for="age_min" ng-show="submittab2 && !attributesForm2.age_min.$error.positive && !attributesForm2.age_min.$error.maxlength && attributesForm2.age_min.$error.min" class="error">{{formValidation.minMax}}</label>
                                                    <label for="age_min" ng-show="submittab2 && !attributesForm2.age_min.$error.positive && !attributesForm2.age_min.$error.maxlength && attributesForm2.age_min.$error.number" class="error">{{formValidation.errorNumber}}</label>
                                                    <label for="age_min" ng-show="submittab2 && attributesForm2.age_min.$error.positive" class="error">{{formValidation.minpositive}}</label>
                                                </div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

angularjs:只允许在文本框中键入数字

如何在ReactJS的文本框中仅允许数字?

如何在文本框中只允许电话号码并自动将它们隔开?

如何只允许数字和一个小数点在Web窗体文本框中

只允许在文本框中键入数字

只允许数字进入输入文本框

C#Winforms中的文本框验证-应该只允许1-100之间的数字

如何在文本框中仅允许十进制数字

如何在HTML文本框中仅允许4位数字?

Angular:如何使用指令在文本框中只允许整数

当只允许字母时,如何让两个不同的文本框确定是否输入数字?

什么是正则表达式 ValidationExpression 只允许文本框中的数字 1 到 100?

只允许在文本框中键入数字-默认为零

如何在SmartGWT中验证仅数字文本框?

如何在angularJs Factory中检查文本框isEmpty?

如何旋转框只允许数字

如何在 Swal Sweetalert 中只允许数字

如何限制输入文本框只允许 0 和 1

如何限制只允许整数,特别是千位的文本框?

在输入文本框中仅允许数字

只允许文本框中的前两个和最后两个是字母,中间是数字(例如 EE123456789IN)

如何不允许用户在文本框中输入数字

如何在React JS中仅允许文本框中的数字和格式作为美国手机号码格式?例如:(224)-5623 -2365

如何在Django的数字字段的文本框中删除数字增量

如何只允许数字?

如何只允许在jTextField中引入数字?

通过angularjs中的提示框只允许字母数字字符

如何验证文本框中的文本和数字?

如何在文本框中计算数字