function checkEmail(){
var email=document.getElementById("email").value;
var email_prompt=document.getElementById("email_prompt");
email_prompt.innerHTML="";
email_prompt.innerHTML="电子邮件格式不正确,请重新输入";
return false;
}
return true;
var email=document.getElementById("email").value;
var email_prompt=document.getElementById("email_prompt");
email_prompt.innerHTML="";
var reg=/^\w+@\w+(\.[a-zA-Z]{2,3}){1,2}$/;
if(email==""){
email_prompt.innerHTML="Email不能为空";
return false;
}
if(email.indexOf("@")==-1){
email_prompt.innerHTML="Email格式不正确\n必须包含@";
return false;
}
if(email.indexOf(".")==-1){
email_prompt.innerHTML="Email格式不正确\n必须包含.";
return false;
}
email_prompt.innerHTML="电子邮件格式不正确,请重新输入";
return false;
}
return true;
}
<tr>
<td class="left">电子邮件:</td>
<td><input id="email" type="text" name="email" class="inputs" οnblur="checkEmail()" /><div id="email_prompt" class="prompt"></div></td>
</tr>