js和php邮箱地址验证的实现方法
时间:2024-06-05 09:38:13
邮箱地址验证有很多方法。在浏览器端,js邮箱验证可以通过正则表达式检测。
比如:
function isEmail(email) {
return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(email);
}
调用很简单:
if (isEmail('youremail@yourdomain.com')){ console.log('This is email is valid'); }
如果是进行服务器端验证。像php,则最简单的莫过于:
/*
* 邮箱地址合法性验证
*/
function isEmail($mail_address) {
return filter_var($mail_address, FILTER_VALIDATE_EMAIL);
}
但是这个件事也可以整得复杂。
像这位。他建立起一整套的邮箱地址验证网站体系。估计很少人这么干。
说实话,不得不佩服。
标签:邮箱地址验证
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
结合Python的SimpleHTTPServer源码来解析socket通信
2021-09-05 23:30:27
![](https://img.aspxhome.com/file/2023/6/105046_0s.jpg)
用 Schema 约束 XML 数据
2010-08-24 18:21:00
![](https://img.aspxhome.com/file/UploadPic/20108/24/20100814231755976-28s.gif)
php之php.ini配置文件讲解案例
2023-06-11 18:19:06
Python Sqlalchemy如何实现select for update
2022-01-23 02:26:31
![](https://img.aspxhome.com/file/2023/7/133587_0s.png)
mysql索引必须了解的几个重要问题
2024-01-27 17:58:54
MySQL注入绕开过滤的技巧总结
2024-01-14 10:42:52
![](https://img.aspxhome.com/file/2023/5/108915_0s.gif)
Go语言开发发送Get和Post请求的示例
2024-05-21 10:23:46
Python实现PS滤镜特效之扇形变换效果示例
2021-05-08 17:58:03
![](https://img.aspxhome.com/file/2023/4/128504_0s.jpg)
日常整理python执行系统命令的常见方法(全)
2022-07-30 10:39:45
sqlserver substring函数使用方法小结
2024-01-19 17:53:03
Golang pipe在不同场景下远程交互
2024-05-09 09:45:58
JavaScript 浮动定位提示效果实现代码第1/2页
2023-07-22 23:26:19
![](https://img.aspxhome.com/file/2023/5/55945_0s.jpg)
PHP实时统计中文字数和区别
2023-07-13 10:44:01
Go 实现 WebSockets之创建 WebSockets
2024-05-09 09:30:36
![](https://img.aspxhome.com/file/2023/3/128703_0s.png)
Python中常用的8种字符串操作方法
2023-05-28 09:44:38
![](https://img.aspxhome.com/file/2023/6/87886_0s.jpg)
Python Web框架之Django框架Model基础详解
2023-11-04 22:07:00
Python接口自动化之浅析requests模块get请求
2021-12-07 07:20:45
![](https://img.aspxhome.com/file/2023/8/131168_0s.png)
python如何通过psutil获取服务器cpu、内存、磁盘使用率
2022-11-07 01:01:29
利用django model save方法对未更改的字段依然进行了保存
2021-12-21 21:24:18
![](https://img.aspxhome.com/file/2023/3/124973_0s.jpg)
如何用Python对数学函数进行求值、求偏导
2023-10-13 04:58:01