今天看了一段代码,是关于邮箱的验证的,怕自己忘记了,就写了一下,和大家分享一下
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script>
window.onload = function() {
}
function dianjishijian() {
var x = document.getElementById("youxiang").value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {
alert("请输入正确的邮箱地址");
return false;
}
}
</script>
</head>
<body>
<input type="text" name="youxiang" id="youxiang" value="" />
<button id="" onclick="dianjishijian()">点击试试</button>
</body>
</html>
原文地址:http://blog.csdn.net/li_li_lin/article/details/38872483