2013年9月7日 星期六

E-mail 格式檢查

示範


JS Code
<script type="text/javascript">

function validateEmail()
{
var emailvalue=document.forms["emailform"]["email"].value;
var atpos=emailvalue.indexOf("@");
var dotpos=emailvalue.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=emailvalue.length)
  {
  alert("請輸入正確電子信箱");
  return false;
  }
}

</script>



Html Code
<form action="emailform.php" method="post" enctype="application/x-www-form-urlencoded" name="emailform" id="emailform" onsubmit="return validateEmail();" target="_blank">

<input name="email" type="text" value="訂閱電子報">
<button type="submit" class="button" id="button" name="button">訂閱</button>

</form>

沒有留言:

張貼留言