你好新手到角js? 一旦用戶輸入十進制值或顯示錯誤的字符串js中的字符串,如何只允許texbox中的數字?如何只允許angularjs中的文本框中的數字?
<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>
我試過上面的代碼,但是輸入十進制值時不顯示錯誤?怎麼解決?
找到答案:http://stackoverflow.com/questions/32777184/html-input-for-positive-whole-numbers-only-type-number – varit05
嘗試使用的輸入類型爲'number'和'模式=「^ [0-9] * $」'屬性 –
可能的重複http://stackoverflow.com/questions/8808590/html5-number-input-type-that-takes-only-integers –