以下代碼加入Html的<body>區:
<script language="Javascript">
<!-- Begin
function chk(email, formname)
{
invalid = "";
if (!email)
invalid = "請輸入您的Email地址。";
else {
if ( (email.indexOf("@") == -1) || (email.indexOf(".") == -1) )
invalid += "\n\nEmail地址不合法。應當包含'@'和'.';例如('.com')。請檢查後再遞交。";
if (email.indexOf("your email here") > -1)
invalid += "\n\nEmail地址不合法,請檢測您的Email地址,在域名內應當包含'@'和'.';例如('.com')。";
if (email.indexOf("\\") > -1)
invalid += "\n\nEmail地址不合法,含有非法字符(\\)。";
if (email.indexOf("/") > -1)
invalid += "\n\nEmail地址不合法,含有非法字符(/)。";
if (email.indexOf("'") > -1)
invalid += "\n\nEmail地址不合法,含有非法字符(')。";
if (email.indexOf("!") > -1)
invalid += "\n\nEmail地址不合法,含有非法字符(!)。";
if ( (email.indexOf(",") > -1) || (email.indexOf(";") > -1) )
invalid += "\n\n只輸入一個Email地址,不要含有分號和逗號。";
if (email.indexOf("?subject") > -1)
invalid += "\n\n不要加入'?subject=...'。";
}
if (invalid == "")
{
return true;
}
else
{
alert("輸入的Email可能包含錯誤:" + invalid);
return false;
}
}
// End -->
</script>
<form method="post" name="myform" action="submit.ASP" onSubmit="return chk(document.myform.email.value)">
<div align="center">
<input type="text" name="email" value="your email here">
<input type="submit" name="Submit" value="Submit">
</div>
</form>