gpt4 book ai didi

jquery - 验证旧密码字段

转载 作者:行者123 更新时间:2023-12-01 07:39:36 25 4
gpt4 key购买 nike

如果未输入旧密码,如何应用验证陷入困境。如果用户忘记输入旧密码,则需要验证。提前致谢。

FIDDLE DEMO

$(document).ready(function() {
$("#submitBtn").click(function(){
validate();
});
});

function validate() {
var password1 = $("#password1").val();
var password2 = $("#password2").val();
if(password1 != password2) {
$(".error-msg").html("Password and confirmation password do not match.").show();
}
else {
$(".error-msg").html("").hide();
ValidatePassword();
}
}

function ValidatePassword() {
var regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$@!%&*?])[A-Za-z\d#$@!%&*?]{8,}$/;
var txt = document.getElementById("password1");
if (!regex.test(txt.value)) {
$(".error-msg").html("The password does not meet the password policy requirements.").show();
} else {
$(".error-msg").html("").hide();
window.location.href='change-password-msg.html';
}
}

最佳答案

您必须首先检查您的旧密码输入是否填写。请查看我的代码也许它可以帮助你。观看直播JSFiddle

HTML 代码 -

<div class="error-msg"></div>
<br><br>

<form>
<div class="form-group">
<label>OLD PASSWORD</label>
<input name="oldPassword" id="oldPassword" type="password" class="form-control">
</div>
<div class="form-group">
<label>NEW PASSWORD</label>
<input type="password" id="password1" class="form-control">
</div>
<div class="form-group">
<label>CONFIRM PASSWORD</label>
<input type="password" id="password2" class="form-control">
</div>
</form>
<button type="button" id="submitBtn" class="btn btn-primary">UPDATE</button>

CSS 代码 -

.error-msg {
width: 100%;
font-family: 'nobelregular';
color: #ff0002;
display: none;
}

JS 代码 -

$(document).ready(function() {
$("#submitBtn").click(function() {
var oldVal = $('#oldPassword').val() || "";
if (oldVal == "") {
$(".error-msg").html("First you have to fill Old Password.").show();
return false;
}
validate();
});
});

function validate() {
var password1 = $("#password1").val();
var password2 = $("#password2").val();
if (password1 != password2) {
$(".error-msg").html("Password and confirmation password do not match.").show();
} else {
$(".error-msg").html("").hide();
ValidatePassword();
}
}

function ValidatePassword() {
var regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$@!%&*?])[A-Za-z\d#$@!%&*?]{8,}$/;
var txt = document.getElementById("password1");
if (!regex.test(txt.value)) {
$(".error-msg").html("The password does not meet the password policy requirements.").show();
} else {
$(".error-msg").html("").hide();
window.location.href = 'change-password-msg.html';
}
}

关于jquery - 验证旧密码字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53113116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com