【发布时间】:2016-07-02 12:24:20
【问题描述】:
嗨,我是 Angular js 的新手吗? 一旦用户在angular 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>
我尝试上面的代码,但是输入十进制值时没有显示错误?如何解决?
【问题讨论】:
-
尝试使用输入类型作为
number和pattern="^[0-9]*$"属性 -
不工作, 添加模式但在添加十进制值时未显示任何错误?如何显示模式验证的错误消息?更改模式也 ^[0-9]*$ 没有显示任何错误仍然接受十进制值
标签: angularjs