繁体   English   中英

用Java进行Formvalidation

[英]Formvalidation with Javascript

我想验证我的表单,但我坚持使用formfield persnr的验证。 它不会比较字符串。 为此,我已经尝试了比较和运算符(或||)。 其他字段的验证是可以的。 我用错了运算符吗?

function checkForm() {
    var strFehler = '';
    if (document.forms[0].user.value == "user")
        strFehler += "user not ok!\n";
    if (document.forms[0].test.value == "")
        strFehler += "test not ok!\n";
    if (document.forms[0].time.value == "")
        strFehler += "time not ok";
    if (document.forms[0].cost.value == "")
        strFehler += "cost not ok!\n";
    if (document.forms[0].persnr.value != "13088") || (document.forms[0].persnr.value != "10286")
    strFehler += "persnr false!\n";
    if (strFehler.length > 0) {
        alert("problems!!: \n\n" + strFehler);
        return (false);
    }
}

我希望如果该值不是13088或10286,但没有弹出消息,验证将显示警报。

这个:

if (document.forms[0].persnr.value != "13088") || (document.forms[0].persnr.value != "10286")

需要更改为:

if ((document.forms[0].persnr.value != "13088") || (document.forms[0].persnr.value != "10286"))

您缺少括号,以使if语句中同时包含两个条件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM