提醒无效

时间:2009-08-08 01:11:20

标签: javascript

  

可能重复:
  Post Method Not giving Alerts like planned?

使用Javascript:
    

function isAlphanumeric(elem, helperMsg){
    var alphaExp = /^[0-9a-zA-Z]+$/;
    if(elem.value.match(alphaExp)){
        return true;
    } else {
        alert(helperMsg);
        elem.focus();
        return false;
    }
}

function isGoodPhrase(elem,helperMsg){
    var badPhrase=/EPW|ESW|\s/;
    if (elem.value.match(badPhrase)){
        alert(helperMsg);
        elem.focus();
        return false;
    } else {
        return true;
    }
}

function checkInput(id)    {
    return isAlphanumeric(document.getElementById(id),'Your Submission Contained Invalid Characters')
        && isGoodPhrase(document.getElementById(id), 'Please Enter A Correct Friend Code!');
    }

    </script>

和HTML

    <form action="" method="post">
    <div align="center"><legend>Add a Code</legend>
    <label for="code"></label>
    <input type="text" name="code" id="code" maxlength="10" />
    <input type='button' onclick="return checkInput('code');" value='Check Field' />
    </form>
    </div>

1 个答案:

答案 0 :(得分:0)

警报正常,我测试了它们。

使用与正则表达式不匹配的正确值检测您正在测试的问题以查看警报