gpt4 book ai didi

javascript - 检查密码和确认密码是否相同的验证不起作用

转载 作者:行者123 更新时间:2023-11-30 07:11:37 24 4
gpt4 key购买 nike

这是我的代码:

function validate_form(thisform)
{
with (thisform)
{
if (validate_required(name,"Name must be filled out!")==false)
{name.focus();return false;}
if (validate_required(country," Country must be filled out!")==false)
{country.focus();return false;}
if (validate_required(state,"State must be filled out!")==false)
{state.focus();return false;}
if (validate_required(city,"City must be filled out!")==false)
{city.focus();return false;}
if (validate_required(contact,"Contact must be filled out!")==false)
{contact.focus();return false;}
if (validate_required(emailid,"Email must be filled out!")==false)
{emailid.focus();return false;}
if (validate_email(userid,"Email is not valid")==false)
{userid.focus();return false;}
if (validate_required(password,"pasword must be filed out")==false)
{password.focus();return false;}
if (validate_required(cpassword,"Password must be confirmed")==false)
{cpassword.focus();return false;}

if(validate_required((password.value != cpassword.value),"Your password and confirmation password do not match.")==false) {
cpassword.focus();return false;


}

所有其他验证均有效,但最后一个无效。为什么会这样,如何解决?

最佳答案

我假设您已经从这个页面获得了 validate_required() 函数:http://www.w3schools.com/js/js_form_validation.asp

function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
}

在这种情况下,您的最后一个条件将不会像您预期的那样工作。

您可以将其替换为:

if (password.value != cpassword.value) { 
alert("Your password and confirmation password do not match.");
cpassword.focus();
return false;
}

关于javascript - 检查密码和确认密码是否相同的验证不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3093176/

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