我正在使用跨度显示密码规则。我想在满足输入条件时动态删除每个包含规则的范围。我可以删除最小长度跨度,但是不知道如何删除其他人。
这是我的HTML代码:
<input name="user_password" ng-minlength="8" ng-model="passForm.user_password1" id="user_password" type="password">
<label class="left-align" for="user_password">Password*</label>
</div>
<div class="input-field col s12">
<input name="user_password_confirm" ng-model="passForm.user_password2" id="user_password_confirm"
type="password" class="validate">
<span style="color:red" ng-if="passForm.user_password2 && passForm.user_password1 != passForm.user_password2">
<ul>Confirm password do not match.</ul>
</span>
<span style="color:red; display: block !important;">
Password should honor following rules:<br>
</span>
<span style="color:red; display: block !important;" ng-if="!passForm.user_password1 || passForm.user_password1.$error.minlength">
- minimun 8 charactes<br>
</span>
<span style="color:red; display: block !important">
- atleast 1 uppercase character<br>
- atleast 1 lowercase character<br>
- atleast 1 digit<br>
- atleast 1 special character [@$!#%*?&.]<br>
</span>
还有我的控制器:
$scope.changeUserPassword = function(){
var eFlag = false;
$scope.errors = {};
var rePassword = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&#.])[A-Za-z\d$@$!%*?&#.]{8,}/;
if ($scope.passForm.user_password1 && rePassword.test($scope.passForm.user_password1) == false) {
swal('Error!', "Please enter a password honoring rules in hint",'error');
eFlag = true;
}
答案 0 :(得分:0)
我会说自己制定每个规则,并相应地删除span标签。
那是
var rule1 = /^[^A-Z]*[A-Z]/;
if (rule1.test($scope.passForm.user_password1)) {
// remove the span for the uppercase here
});
var rule2 = /^[^a-z]*[a-z]/;
if (rule2.test($scope.passForm.user_password1)) {
// remove the span for the lowercase here
});
以此类推。将所有规则放在一个数组中并遍历它们。