3
请帮助,如何验证此多个密码并确认密码是否相等?如果第一个judge_password []和juge_conPassword []不相等,则返回false,然后再次迭代到下一个。Javascript:验证多个密码并确认密码字段
<input type="password" name="judge_password[]" class="judge_password">
<input type="password" name="judge_conPassword[]" class="judge_conPassword">
<input type="password" name="judge_password[]" class="judge_password">
<input type="password" name="judge_conPassword[]" class="judge_conPassword">
<input type="password" name="judge_password[]" class="judge_password">
<input type="password" name="judge_conPassword[]" class="judge_conPassword">
<input type="button" id="click">
我的代码
var judge_conPassword = [];
$('.judge_conPassword').each(function(){
var theVal = $(this).val();
if($.trim($(this).val())==''){
pralse = false;
$('.trigger_danger_alert_changable').show().delay(5000).fadeOut();
$('#palitan_ng_text').html('Confirm password required');
return false;
}
judge_conPassword.push(theVal);
});
var judge_password = [];
$('.judge_password').each(function(){
var theVal = $(this).val();
if($.trim($(this).val())==''){
pralse = false;
$('.trigger_danger_alert_changable').show().delay(5000).fadeOut();
$('#palitan_ng_text').html('Password cannot be empty');
return false;
}
judge_password.push(theVal);
});
if(!pralse){
return false;
}
function checkPass(judge_password, judge_conPassword){
if(judge_password.length !== judge_conPassword.length){
alert('password missing')
}else{
var j_count = judge_password.length;
for(var i=0; i<j_count; i++){
if(judge_password[i] !== judge_conPassword[i]){
alert('Password not same');
return false;
}
}
return true;
}
}
checkPass();
您可以将这些字段的值存储在两个单独的阵列和比较这些值 –
有什么问题了吗?你的代码看起来很好。 –
@ HiI'mFrogatto他缺少.value,而比较 –