可直接複製下列程式碼
<body>
<form name="form" method="post" action="index.php" >
<div><label for="email">電子信箱:</label>
<input type="text" style="width:220px;" name="email" id="email"/></div>
<input type='submit' id ='ok' name='ok' value='送出' >
</form>
</body>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.min.js"></script>
<Script Language='JavaScript'>
$('#ok').click(function() {
if(document.getElementById('email').value.length >=5 && document.getElementById('email').value.match(/^[0-9a-zA-Z]([-._]*[0-9a-zA-Z])*@[0-9a-zA-Z]([-._]*[0-9a-zA-Z])*\.+[a-zA-Z]+$/)){
//判斷Email長度及符合Email格式,必須符合 xxx@xxxx.xxx 並且不包括其他特殊字元
alert('OK');
}
else{
alert('請輸入正確的Email!!');
return false;
}
});
</script>