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

运维工程师,快来薅羊毛

markdown编辑器模板

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

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

OpenCV3.0 兼容VS2010与VS2013的问题
![[Day6] File system permission management, file special permissions, hidden attributes](/img/ec/7fb3fa671fac8abf389844c0f4fbe7.png)
[Day6] File system permission management, file special permissions, hidden attributes

硬核!Cocos开发面试必备十问,让你offer拿到手软

Cocos Creator小游戏案例《棍子士兵》

技术分享杂七杂八技术

Getting Started Document 01 series in order
随机推荐
ACLs and NATs
网站ICP备案是什么呢?
D41_缓冲池
D46_给刚体施加的力
D45_摄像机组件Camera
Spark源码-任务提交流程之-6-sparkContext初始化
[Paper Intensive Reading] The relationship between Precision-Recall and ROC curves
dsf5.0新建页面访问时重定向到首页的问题
CIPU,对云计算产业有什么影响
The problem of calling ds18b20 through a single bus
Spark source code - task submission process - 4-container to start executor
【Day8】Knowledge about disk and disk partition
spark operator-parallelize operator
spark operator - map vs mapPartitions operator
Getting Started 04 When a task depends on another task, it needs to be executed in sequence
Getting Started 11 Automatically add version numbers
Getting Started Documentation 10 Resource Mapping
Unity物理引擎中的碰撞、角色控制器、Cloth组件(布料)、关节 Joint
入门文档10 资源映射
Getting Started Doc 08 Conditional Plugins