请帮我看看邮件验证程序不行
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<Script language="javascript" >
function validate_form() {
validity = true;
if (!check_empty(document.form.name.value))
{ validity = false; alert( 'Sorry!Please Fill in your name '); }
if (!check_email(document.form.email.value))
{ validity = false; alert( 'Sorry!Please Fill in the correct Email address '); }
if (!check_empty(document.form.company.value))
{ validity = false; alert( 'Sorry!Please Fill in your company '); }
if (validity)
alert (" Thanks for your register, "
+ " we will inform you soon ");
return validity;
}
function check_empty(text) {
return (text.length > 0);
}
function check_email(address) {
if ((address == "")
¦ ¦ (address.indexOf ( '@ ') == -1)
¦ ¦ (address.indexOf ( '. ') == -1))
return false;
return true;
}
</Script>
<body >
<form name="form" onSubmit="return validate_form()" method="post" action="mailto:duji0002@ntu.edu.sg?subject=Register Training" enctype="text/plain" >
<p>You can press "Ctrl" for multiple selection </p>
<p>
<Select Name="The Trainings" Multiple>
<Option value="1.Grounding type according to IEC 60364-4-41 and their protection" Selected>Grounding type according to IEC 60364-4-41 and their protection</Option>
<Option value="2.Power Quality problem and the mitigation solutions">Power Quality problem and the mitigation solutions</Option>
<Option value="3.Lightning protection earth measurement and soil resistivity measurement">Lightning protection earth measurement and soil resistivity measurement</Option>
<Option value="4.Power factor and harmonics correction">Power factor and harmonics correction</Option>
<Option value="5.Communication protocol & software training">Communication protocol & software training</Option>
</Select>
</p>
<p align="center" > <font size="3" > <b > <font size="4" face="Verdana, Arial, Helvetica, sans-serif" >Name </font >: </b > </font >
<input name="name" type="text" id="name" size=46 >
<br >
<b > <font size="4" face="Verdana, Arial, Helvetica, sans-serif" >Email </font > <font size="4" > </font > <font size="3" >: </font > </b >
<input name="email" type="text" id="email" size=46 >
<br >
<b > <font size="4" face="Verdana, Arial, Helvetica, sans-serif" >Company </font > <font size="4" > </font > <font size="3" >: </font > </b >
<input name="company" type="text" id="company" size=46 >
<br >
<b > <font size="4" face="Verdana, Arial, Helvetica, sans-serif" >Telephone </font > <font size="4" > </font > <font size="3" >: </font > </b >
<input name="telephone" type="text" id="telephone" size=46 >
<br >
<b > <font size="4" face="Verdana, Arial, Helvetica, sans-serif" >Comments </font > <font size="4" > </font > <font size="3" >: </font > </b >
<br >
<textarea name="comments" rows=8 cols=45 wrap=virtual id="txt" > </textarea >
</p >
</div > </td >
</tr >
<tr >
<td >
<div align="center" >
<div align="center" >
<br >
<input type="submit" value="Send">
<input type="reset" value="Reset">
</div >
</form >
</body >
</html >
[解决办法]
<html >
<head >
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" / >
<title >Untitled Document </title >
</head >
<Script language="javascript" >
function validate_form() {
validity = true;
if (!check_empty(document.form.name.value))
{
alert( 'Sorry!Please Fill in your name ');
return false;
}
if (!check_email(document.form.email.value))
{
alert( 'Sorry!Please Fill in the correct Email address ');
return false;
}
if (!check_empty(document.form.company.value))
{
alert( 'Sorry!Please Fill in your company ');
return false;
}
return true;
}
function check_empty(text) {
return (text.length > 0);
}
function check_email(email) {
//var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
var pattern = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
flag = pattern.test(email);
if(!flag&&email.length>0){
return false;
}
return true;
}
</Script >
<body >
<form name="form" onSubmit="return validate_form()" method="post" action="mailto:duji0002@ntu.edu.sg?subject=Register Training" enctype="text/plain" >
<p >You can press "Ctrl" for multiple selection </p >
<p >
<Select Name="The Trainings" Multiple >
<Option value="1.Grounding type according to IEC 60364-4-41 and their protection" Selected >Grounding type according to IEC 60364-4-41 and their protection </Option >
<Option value="2.Power Quality problem and the mitigation solutions" >Power Quality problem and the mitigation solutions </Option >
<Option value="3.Lightning protection earth measurement and soil resistivity measurement" >Lightning protection earth measurement and soil resistivity measurement </Option >
<Option value="4.Power factor and harmonics correction" >Power factor and harmonics correction </Option >
<Option value="5.Communication protocol & software training" >Communication protocol & software training </Option >
</Select >
</p >
<p align="center" > <font size="3" > <b > <font size="4" face="Verdana, Arial, Helvetica, sans-serif" >Name </font >: </b > </font >
<input name="name" type="text" id="name" size=46 >
<br >
<b > <font size="4" face="Verdana, Arial, Helvetica, sans-serif" >Email </font > <font size="4" > </font > <font size="3" >: </font > </b >
<input name="email" type="text" id="email" size=46 >
<br >
<b > <font size="4" face="Verdana, Arial, Helvetica, sans-serif" >Company </font > <font size="4" > </font > <font size="3" >: </font > </b >
<input name="company" type="text" id="company" size=46 >
<br >
<b > <font size="4" face="Verdana, Arial, Helvetica, sans-serif" >Telephone </font > <font size="4" > </font > <font size="3" >: </font > </b >
<input name="telephone" type="text" id="telephone" size=46 >
<br >
<b > <font size="4" face="Verdana, Arial, Helvetica, sans-serif" >Comments </font > <font size="4" > </font > <font size="3" >: </font > </b >
<br >
<textarea name="comments" rows=8 cols=45 wrap=virtual id="txt" > </textarea >
</p >
</div > </td >
</tr >
<tr >
<td >
<div align="center" >
<div align="center" >
<br >
<input type="submit" value="Send" >
<input type="reset" value="Reset" >
</div >
</form >
</body >
</html >
