表单递交合法性检测-EMAIL
类别: JavaScript教程
以下代码加入HTML的<body>区:
<script language="javascript">
<!-- Begin
function chk(email, formname)
{
invalid = "";
if (!email)
invalid = "请输入您的Email地址。";
else {
if ( (email.indexOf("@") == -1) || (email.indexOf(".") == -1) )
invalid += "nnEmail地址不合法。应当包含\'@\'和\'.\';例如(\'.com\')。请检查后再递交。";
if (email.indexOf("your email here") > -1)
invalid += "nnEmail地址不合法,请检测您的Email地址,在域名内应当包含\'@\'和\'.\';例如(\'.com\')。";
if (email.indexOf("\\") > -1)
invalid += "nnEmail地址不合法,含有非法字符(\\)。";
if (email.indexOf("/") > -1)
invalid += "nnEmail地址不合法,含有非法字符(/)。";
if (email.indexOf("\'") > -1)
invalid += "nnEmail地址不合法,含有非法字符(\')。";
if (email.indexOf("!") > -1)
invalid += "nnEmail地址不合法,含有非法字符(!)。";
if ( (email.indexOf(",") > -1) || (email.indexOf(";") > -1) )
invalid += "nn只输入一个Email地址,不要含有分号和逗号。";
if (email.indexOf("?subject") > -1)
invalid += "nn不要加入\'?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>
<script language="javascript">
<!-- Begin
function chk(email, formname)
{
invalid = "";
if (!email)
invalid = "请输入您的Email地址。";
else {
if ( (email.indexOf("@") == -1) || (email.indexOf(".") == -1) )
invalid += "nnEmail地址不合法。应当包含\'@\'和\'.\';例如(\'.com\')。请检查后再递交。";
if (email.indexOf("your email here") > -1)
invalid += "nnEmail地址不合法,请检测您的Email地址,在域名内应当包含\'@\'和\'.\';例如(\'.com\')。";
if (email.indexOf("\\") > -1)
invalid += "nnEmail地址不合法,含有非法字符(\\)。";
if (email.indexOf("/") > -1)
invalid += "nnEmail地址不合法,含有非法字符(/)。";
if (email.indexOf("\'") > -1)
invalid += "nnEmail地址不合法,含有非法字符(\')。";
if (email.indexOf("!") > -1)
invalid += "nnEmail地址不合法,含有非法字符(!)。";
if ( (email.indexOf(",") > -1) || (email.indexOf(";") > -1) )
invalid += "nn只输入一个Email地址,不要含有分号和逗号。";
if (email.indexOf("?subject") > -1)
invalid += "nn不要加入\'?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>
- 上一篇: 表单递交合法性检测-日期
- 下一篇: 到亿位的金额小写转大写JS代码
-= 资 源 教 程 =-
文 章 搜 索