簡體   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