我是AngularJS中的新成員。我想爲輸入設置驗證,如最小長度爲5,最大長度爲6.AngularJS ng-minlength ng-required not working
我必須設置5到6僅數字到我的文本框中。
對於這個我使用下面的代碼,但它不工作
<div class="input-wrap lg-input">
<input type="text" name="num" class="form-input" placeholder="Enter 5-6 digits" ng-minlength="5" maxlength="6"
ng-model="profInfo.Number" ng-required="true">
<div class="error" ng-show="profInfoForm.$submitted || profInfoForm.num.$touched">
<span ng-show="profInfoForm.num.$error.required">Required Field</span>
<span ng-show="profInfoForm.num.$error.minlength">Invalid input</span>
</div>
</div>
<div class="button-ctr">
<button class="button" ng-class="profInfoForm.$valid ? 'active' : 'disable'">Next</button>
</div>
目前這一工作象下面這樣:
當文本框是空的,我點擊下一步按鈕,它顯示必填字段錯誤消息是正確的。
我輸入的數字不能超過6位。
當我在文本框中輸入1位數字並點擊按鈕時,它顯示錯誤的必填字段錯誤消息。
當我鍵入第5位數字時,顯示錯誤的無效輸入錯誤消息。
我正在使用AngularJS v1.5.5。
你能解釋「它不工作」的一部分?你期望什麼,以及它如何表現? –
爲什麼使用maxlength來支持ng-maxlength? – DevDig
@DevDig我希望該用戶不能輸入大於6位數的輸入。 – user3441151