当前位置:网站首页>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
边栏推荐
- D39_向量
- 入门文档05 使用cb()指示当前任务已完成
- I217-V network disconnection problem in large traffic under openwrt soft routing
- Hugo搭建个人博客
- VRRP原理及命令
- 【Day8】(超详细步骤)使用LVM扩容
- [Paper Intensive Reading] Rich Feature Hierarchies for Accurate Object Detection and Semantic Segmentation (R-CNN)
- 【Day8】Knowledge about disk and disk partition
- D41_缓冲池
- 入门文档12 webserve + 热更新
猜你喜欢

Getting Started Documentation 12 webserve + Hot Updates

硬盘分区和永久挂载

Unity3D中的ref、out、Params三种参数的使用

spark source code - task submission process - 1-sparkSubmit
![[Pytorch study notes] 8. How to use WeightedRandomSampler (weight sampler) when the training category is unbalanced data](/img/29/5b44c016bd11f0c0a9110cf513f4e1.png)
[Pytorch study notes] 8. How to use WeightedRandomSampler (weight sampler) when the training category is unbalanced data

错误类型:reflection.ReflectionException: Could not set property ‘xxx‘ of ‘class ‘xxx‘ with value ‘xxx‘

Getting Started Doc 06 Adding files to a stream

dsf5.0 弹框点确定没有返回值的问题

Account and Permission Management
![[Day6] File system permission management, file special permissions, hidden attributes](/img/ec/7fb3fa671fac8abf389844c0f4fbe7.png)
[Day6] File system permission management, file special permissions, hidden attributes
随机推荐
2020年手机上最好的25种免费游戏
账号与权限管理
Call the TensorFlow Objection Detection API for object detection and save the detection results locally
SSL证书提示过期或者无效,该怎么处理呢?
入门文档12 webserve + 热更新
VLAN详解及实验
spark operator-textFile operator
D39_欧拉角与四元数
spark算子-map vs mapPartitions算子
腾讯云云函数SCF—入门须知
TCP/IP四层模型
洞察互联网大趋势,读完这篇文章你就彻底了解中文域名
Getting Started 11 Automatically add version numbers
【Day1】(超详细步骤)构建软RAID磁盘阵列
markdown编辑器模板
[Day6] File system permission management, file special permissions, hidden attributes
静态路由
入门文档05 使用cb()指示当前任务已完成
The spark operator - repartition operator
spark source code - task submission process - 5-CoarseGrainedExecutorBackend