1. 程式人生 > >判斷郵箱是否有效

判斷郵箱是否有效

判斷郵箱 是否有效


<form action="submitpage.htm"onsubmit="return validate_form(this);" method="post">

Email: <input type="text" name="email" size="30">

<input type="submit" value="Submit">

</form>

<script type="text/javascript">
function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@")
dotpos=value.lastIndexOf(".")
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false}
else {return true}
}
}

function validate_form(thisform)
{
with (thisform)
{
if (validate_email(email,"不是有效的電子郵件地址!")==false)
  {email.focus();return false}
}
}
</script>


判斷郵箱是否有效