Cra*_*oiD 2 html validation angularjs angularjs-directive ionic-framework
我有这个文本字段,我需要阻止用户输入超过允许的字符.让我们说我希望用户只键入10个字符,如果他输入更多文本字段将不会采取它.它必须在达到字符限制后停止获取输入..
我知道有ng-maxlength但它不会阻止用户输入超过允许的字符,虽然我可以给出一个错误信息.有没有办法做到这一点.
我的文字字段
<div class="form-group" ng-class="{ 'has-error' : submitted && (thirdPartyForm.beneAcc.$pristine || thirdPartyForm.beneAcc.$invalid )}">
<label class="labelColor"><h5><b>Beneficiary Account/Card Number*</b></h5></label>
<input ng-keyup="validateCreditCard();" onkeypress="return ((event.charCode > 64 && event.charCode < 91) || (event.charCode > 96 && event.charCode < 123) || event.charCode == 8 || event.charCode == 45 || event.charCode == 32 || (event.charCode >= 48 && event.charCode <= 57))" type="{{inputType}}" ng-click="inputClick()" id="beneAcc" name="beneAcc" ng-model="data.beneAcc" class="form-control" ng-blur="validateDesitinationAccount(data.origin, data.beneAcc);" required>
<span class="help-inline" ng-show="submitted && (thirdPartyForm.beneAcc.$pristine || thirdPartyForm.beneAcc.$invalid )">Beneficiary Account No cannot be left blank.</span>
<span class="help-inline" ng-show="validateAccFlag" style="color:red" >{{validateMsgStr}}</span>
<span class="help-inline" style="color:red;" ng-if="LkrValidation">You cannot transfer Sri Lankan Rupees to foreign currency accounts.</span>
<span class="help-inline" style="color:red;" ng-show ="accountNoFlag">{{accountNoValidateMsg}}</span>
</div>
Run Code Online (Sandbox Code Playgroud)
如果要将输入限制为特定长度,则使用maxlength而不是ng-maxlength.
<input ng-model="num1" type="text" maxlength="3"></input>
Run Code Online (Sandbox Code Playgroud)
参考 http://jsfiddle.net/xmkLmLms/
| 归档时间: |
|
| 查看次数: |
7025 次 |
| 最近记录: |