当前位置:网站首页>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
边栏推荐
- Getting Started 05 Using cb() to indicate that the current task is complete
- Unity3D中的ref、out、Params三种参数的使用
- 云游戏未来展望
- Mongodb查询分析器解析
- [Day5] Soft and hard links File storage, deletion, directory management commands
- 【Day1】(超详细步骤)构建软RAID磁盘阵列
- 腾讯云云函数SCF—入门须知
- 你要找的cocos面试答案都在这里了!
- VRRP principle and command
- 入门文档11 自动添加版本号
猜你喜欢

I/O性能与可靠性

线上问题排查流程

Getting Started 11 Automatically add version numbers

Contextual non-local alignment of full-scale representations

Getting Started 05 Using cb() to indicate that the current task is complete
![[Day1] (Super detailed steps) Build a soft RAID disk array](/img/40/cda8e5522c2795e03c0d47e8a689f8.png)
[Day1] (Super detailed steps) Build a soft RAID disk array
![[Paper Intensive Reading] Rich Feature Hierarchies for Accurate Object Detection and Semantic Segmentation (R-CNN)](/img/a7/fc3fe440f5e57362d44ae875b7d436.png)
[Paper Intensive Reading] Rich Feature Hierarchies for Accurate Object Detection and Semantic Segmentation (R-CNN)

OpenCV3.0 is compatible with VS2010 and VS2013

【Day8】RAID Disk Array

Unity3D中的ref、out、Params三种参数的使用
随机推荐
洞察互联网大趋势,读完这篇文章你就彻底了解中文域名
云计算——osi七层与TCP\IP协议
D46_给刚体施加的力
入门文档06 向流(stream)中添加文件
spark源码-任务提交流程之-4-container中启动executor
D39_坐标转换
[Day8] (Super detailed steps) Use LVM to expand capacity
交换机原理
正则表达式小实例--验证邮箱地址
运维工程师,快来薅羊毛
D45_摄像机组件Camera
账号与权限管理
[Pytorch study notes] 8. How to use WeightedRandomSampler (weight sampler) when the training category is unbalanced data
小度 小度 在呢!
[Day1] (Super detailed steps) Build a soft RAID disk array
The spark operator - repartition operator
Getting Started Doc 08 Conditional Plugins
Three modes of vim
专有宿主机CDH
入门文档08 条件插件