javascript - 如果满足密码条件,则删除跨度
问题描述
我正在使用 span 显示密码规则。我想在满足输入条件时动态删除每个包含规则的跨度。我能够删除最小长度跨度,但不知道如何删除其他跨度。
这是我的 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;
}
解决方案
我会说自己制定每条规则并相应地删除跨度标签。
那是
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
});
等等。将所有规则放在一个数组中并循环它们。
推荐阅读
- c# - 如何在服务创建期间将 Windows 服务启动类型设置为自动(延迟启动)?
- javascript - 更新开普勒地图中的数据 addDataToMap
- excel - Real-Statistics Excel Add-on LJUNG 公式
- azure - CLI 命令提供来自订阅的资源列表,其中用户是所有者角色
- google-cloud-vision - 谷歌对象本地化中使用的标签列表
- wordpress - 子域重定向到域
- google-cloud-platform - 无法打开当前工作目录的路径:尝试在 gcloud 中运行 rsync 命令两次时权限被拒绝
- java - 使用 SpringBoot 无法访问 H2 数据库控制台
- string - Bash 字符串操作
- angular - 为什么我的 observable 没有返回值?