0
我有一個密碼,它應該是最少8個字符,帶有字母數字和符號,除了&,「,%.I給定了ng-pattern和restricted幾個符號。但是當我輸入&時它也接受。這個ng-pattern通常起作用。當你輸入&和$時,它同時接受。而它不應該允許&。這就是我的一點通過ng-pattern在輸入字段中限制少量特殊字符
<div class="form-group fields col-xs-12 col-sm-6 col-md-4 col-lg-4" ng-class="{'has-error' : (submitted || tForm.password.$dirty || tForm.submitted) && tForm.password.$invalid }">
<input type="password" name="password" placeholder ="Password*" class="form-control1" autocomplete="off" ng-model="model.password" ng-minlength="8" ng-maxlength="20" required ng-pattern="/(?=.*[a-z])(?=.*[A-Z])(?=.*[[email protected]#$^*)(._-])(?=.*[^a-zA-Z._-])(?=.*[^a-zA-Z._-])/" />
<div ng-show="!tForm.password.$error.required && (tForm.password.$error.minlength || tForm.password.$error.maxlength) && tForm.password.$dirty" class="help-block">Passwords must be between 8 and 20 characters.</div>
<div ng-show="!tForm.password.$error.required && !tForm.password.$error.minlength && !tForm.password.$error.maxlength && tForm.password.$error.pattern && tForm.password.$dirty" class="help-block">Must contain one lower & uppercase letter, number and one non-alpha character (except %,",")</div>
<div ng-show="(submitted && tForm.password.$error.required) " class="help-block">password is required.</div>
</div>
嗨,這將工作。但是,當你輸入&和$時,它同時接受。而它不應該允許&。這是我的觀點。 –
爲您編輯代碼。它爲我工作。 –