当前位置:网站首页>Small example of regular expression--validate email address
Small example of regular expression--validate email address
2022-08-05 06:12:00 【CrazyQiQi】
Use regular expressions to verify that the email address is correct
设置一个输入框,一个按钮,A place where information is printed
<label>邮箱:<input type="text" id="email"></label>
<button type="button" id="postEmail">验证邮箱</button>
<p>Print information here</p>
获取输入框、按钮的id,还有p标签节点,Use regular expressions to verify the correctness of the entered email address
//Get the node on which the button was clicked
var post = document.getElementById('postEmail');
post.addEventListener('click', function() {
//给按钮添加2level listener event
//获取p标签节点
var content = document.querySelector('p');
//获取input输入框中的值
var eStr = document.getElementById('email').value;
//正则表达式验证邮箱 例如:
//[email protected]
//[email protected]
//[email protected]
var reg = /^([A-z0-9_-]+)@([A-z0-9_-]+)+(\.([A-z0-9_-]+))+$/g;
if (eStr.match(reg)) {
content.innerHTML = eStr + ' 邮箱正确';
} else {
content.innerHTML = eStr + ' 邮箱有误,请重新输入';
}
})
正确
正确
错误
Let's go into a little more detail about how regular expressions are validated
Two examples of mailboxes
[email protected]
[email protected]
You can see that the email address is basically divided into three parts: [收件人账号]@[邮箱名].[后缀名]
So our regular expression can also be divided into three parts
[Match recipient account(数字/字母//-)]@[邮箱名(数字/字母//-)].[后缀名(数字/字母/_/-)]
var reg = /^([A-z0-9_-]+)@([A-z0-9_-]+)+(\.([A-z0-9_-]+))+$/g;
验证正则表达式
The final track map you can see is like this
边栏推荐
猜你喜欢
TCP/IP four-layer model
spark源码-任务提交流程之-1-sparkSubmit
单臂路由与三成交换机
[Day8] Commands involved in using LVM to expand
2020年手机上最好的25种免费游戏
markdown编辑器模板
解决这三大问题,运维效率将超90%的医院
Unity物理引擎中的碰撞、角色控制器、Cloth组件(布料)、关节 Joint
Remembering my first CCF-A conference paper | After six rejections, my paper is finally accepted, yay!
unity实现第一人称漫游(保姆级教程)
随机推荐
快问快答—腾讯云服务器常见问题解答
腾讯云消息队列CMQ
[Day5] Soft and hard links File storage, deletion, directory management commands
不吹不黑,这的确是我看过微服务架构最好的文章!
unity实现第一人称漫游(保姆级教程)
运维工程师,快来薅羊毛
spark source code - task submission process - 3-ApplicationMaster
单臂路由与三成交换机
[Pytorch study notes] 8. How to use WeightedRandomSampler (weight sampler) when the training category is unbalanced data
spark源码-任务提交流程之-5-CoarseGrainedExecutorBackend
Getting Started 11 Automatically add version numbers
图片压缩失效问题
PVE 直通硬盘到TrueNAS
spark operator-wholeTextFiles operator
I/O性能与可靠性
spark source code - task submission process - 2-YarnClusterApplication
ACL 和NAT
spark operator-textFile operator
markdown编辑器模板
D39_欧拉角与四元数