javascript檢查輸入email是否正確範例
<html>
<head>
<script language="javascript">
function verifyAddress(obj)
{
// obtain form value into variable
var email = obj.value;
alert ('輸入的email為:' + email);
// define regex
var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
// test for pattern
flag = pattern.test(email);
if(flag)
{
alert("正確 e-mail format!");
return true;
}
else
{
alert("輸入e-mail可能有誤!");
return false;
}
}
</script>
</head>
<body>
<form>
<input name="mail" type="text" onBlur="return verifyAddress(this);">
<input type="submit">
</form>
</body>
</html>
沒有留言:
張貼留言