本文摘自PHP中文网,作者angryTom,侵删。

js对用户输入的内容做邮箱验证的方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <!DOCTYPE html>
<html>
<head>
<meta charset= "UTF-8" >
<title>title</title>
</head>
<body>
<!-- 请您输入邮箱地址:<input type= "text" value= "" id= "email" /> *<br/> -->
请您输入邮箱地址:<input type= "text" value= "" id= "email" /> *<br />
<script>
document.getElementById( "email" ).onblur = function () {
var reg = /^[0-9a-zA-Z_.-]+[@][0-9a-zA-Z_.-]+([.][a-zA-Z]+){1,2}$/;
if (reg.test( this .value)) {
this .style.backgroundColor = "green" ;
} else {
this .style.backgroundColor = "red" ;
}
};
</script>
</body>
</html>
|

本文来自 js教程 栏目,欢迎学习!
以上就是js对用户输入的内容做邮箱验证的方法的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
js如何实现随机生成div的效果
如何实现ajax请求?
浅谈javascript中相等操作符:==与===的区别
javascript时间戳如何转化为日期
html实现自动清理js、css文件的缓存
浅谈json.stringify()和json.parse()的应用
微信js是什么
js屏蔽pc端访问
简析如何用js实现简单轮播
10款好看且实用的文字动画特效,让你的页面更吸引人!
更多相关阅读请进入《js》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » js对用户输入的内容做邮箱验证的方法