当前位置:网站首页>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
边栏推荐
猜你喜欢

dsf5.0新建页面访问时重定向到首页的问题

Why can't I add a new hard disk to scan?How to solve?

TCP/IP四层模型

Getting Started Document 01 series in order

Configuration of TensorFlow ObjecDetectionAPI under Anaconda3 of win10 system

2020,Laya最新中高级面试灵魂32问,你都知道吗?

One-arm routing and 30% switch

硬盘分区和永久挂载

【Day8】(超详细步骤)使用LVM扩容

入门文档06 向流(stream)中添加文件
随机推荐
腾讯云云函数SCF—入门须知
什么是阿里云·速成美站?
入门文档01 series按顺序执行
2020年手机上最好的25种免费游戏
spark source code - task submission process - 5-CoarseGrainedExecutorBackend
I217-V network disconnection problem in large traffic under openwrt soft routing
Dsf5.0 bounced points determine not return a value
PVE 直通硬盘到TrueNAS
spark source code - task submission process - 2-YarnClusterApplication
I217-V在openwrt软路由下大流量断网问题
单臂路由与三成交换机
IP地址及子网的划分
图片压缩失效问题
VRRP原理及命令
D45_摄像机组件Camera
入门文档12 webserve + 热更新
Unity物理引擎中的碰撞、角色控制器、Cloth组件(布料)、关节 Joint
OpenCV3.0 兼容VS2010与VS2013的问题
时间复杂度和空间复杂度
海外服务器的优势