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,而比較 –