<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">admin管理员组文章数量:1634824
<html xmlns="http://www.w3/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js验证电子邮箱</title>
<script type="text/javascript">
function check(){
var em=document.getElementById("email");
//非空判断
if(em.value==""||em.length==0){
alert("电子邮件不能为空!");
em.focus();
return false;
}
//读取@和.的索引下标
var at=em.value.indexOf("@"); //-1
var dot=em.value.indexOf(".");
if(at<0||at==0||at==em.value.length-1){
alert("@符号不存在 或者 出现在了首位 或 结尾 都是无效。");
em.focus();
return false;
}
if(dot<0||dot==0||dot==em.value.length-1){
alert(".符号不存在 或者 出现在了首位 或结尾 都是无效");
em.focus();
return false;
}
//sdf@
if(at>=dot-1){
alert("@符号必须出现在.的前面,且两者之间必须有内容");
em.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form οnsubmit="return check()">
请输入电子邮箱:<input type="text" id="email"/>
<input type="submit" value="提交"/>
</form>
</body>
</html>
版权声明:本文标题:js验证电子邮箱 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1729201597a1189680.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论