验证密码并重新输入密码 [英] Validating Password and Retype Password
问题描述
我有两个这样的文本框:
< p><输入类型=文本" name ="NPassword"占位符=新密码"/></p><输入类型=文本" name ="RNPassword"占位符=重新输入新密码"/>
现在,我想要的是在每次键入新密码时都应该检查两者是否相同.如果是,则在RNPassword的右侧以绿色显示它,否则在红色的颜色中显示两者都不是相同,并禁用页面的提交"按钮.如何完成此操作,请帮忙.
尝试此演示: ==> http://jsfiddle.net/ALk9Z/
禁用按钮演示 http://jsfiddle.net/K2Xdc/
以2开头的事情:
- 使用
type = password
〜> http://www.w3.org/TR/html-markup/input.password.html - 使用
.keyup()
API: http://api.jquery.com/keyup/
下次还要在帖子:)
中添加您的JS代码.
代码
HTML
< p><输入类型=密码" name ="NPassword"占位符=新密码" id ="txtNewPassword"/></p><输入类型=密码" name ="RNPassword"占位符=重新输入新密码" id ="txtConfirmPassword" onChange ="isPasswordMatch();"/>< div id ="divCheckPassword"></div>
JS
函数isPasswordMatch(){var password = $(#txtNewPassword").val();var ConfirmPassword = $(#txtConfirmPassword").val();if(密码!= ConfirmPassword)$(#divCheckPassword").html(密码不匹配!");否则$(#divCheckPassword").html(密码匹配.");}$(document).ready(function(){$(#txtConfirmPassword").keyup(isPasswordMatch);});
禁用按钮演示代码
$('#hulk').prop('disabled',true);$('#txtConfirmPassword').on('keyup',function(){var password = $(#txtNewPassword").val();var ConfirmPassword = $(#txtConfirmPassword").val();if(密码!= ConfirmPassword){$(#divCheckPassword").html(密码不匹配!");} 别的 {$(#divCheckPassword").html(密码匹配.");$('#hulk').prop('disabled',false);}});
I am having two textboxes like this :
<p>
<input type="text" name="NPassword" placeholder="New Password"/></p>
<input type="text" name="RNPassword" placeholder="Retype New Password"/>
Now,what i want is that on every keypress of Retype New Password It should check if both are same or not.If yes then in green color display it on right side of RNPassword,Otherwise in red color display that both are not same and also disable the submit button of the page.How this can be done please help.
Try this demo: ==> http://jsfiddle.net/uP8Q2/
Another demo = http://jsfiddle.net/ALk9Z/
disable button demo http://jsfiddle.net/K2Xdc/
2 things to start with:
- use
type=password
~> http://www.w3.org/TR/html-markup/input.password.html - use
.keyup()
API: http://api.jquery.com/keyup/
Also next time add your JS code with the post :)
rest should fit the need.
code
HTML
<p>
<input type="password" name="NPassword" placeholder="New Password" id="txtNewPassword" />
</p>
<input type="password" name="RNPassword" placeholder="Retype New Password" id="txtConfirmPassword" onChange="isPasswordMatch();" />
<div id="divCheckPassword"></div>
JS
function isPasswordMatch() {
var password = $("#txtNewPassword").val();
var confirmPassword = $("#txtConfirmPassword").val();
if (password != confirmPassword) $("#divCheckPassword").html("Passwords do not match!");
else $("#divCheckPassword").html("Passwords match.");
}
$(document).ready(function () {
$("#txtConfirmPassword").keyup(isPasswordMatch);
});
Disable button demo code
$('#hulk').prop('disabled' , true);
$('#txtConfirmPassword').on('keyup', function () {
var password = $("#txtNewPassword").val();
var confirmPassword = $("#txtConfirmPassword").val();
if (password != confirmPassword) {
$("#divCheckPassword").html("Passwords do not match!");
} else {
$("#divCheckPassword").html("Passwords match.");
$('#hulk').prop('disabled' , false);
}
});
这篇关于验证密码并重新输入密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!