php下常用表单验证的正则表达式
时间:2024-05-03 15:35:08
function is_email($str){
//检验email
return preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $str);
}
function is_url($str){
//检验网址
return preg_match("/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"])
*$/", $str);
}
function is_qq($str){
//检验qq
return preg_match("/^[1-9]\d{4,8}$/", $str);
}
function is_zip($str){
//检验邮编
return preg_match("/^[1-9]\d{5}$/", $str);
}
function is_idcard($str){
//检验身份证
return preg_match("/^\d{15}(\d{2}[A-Za-z0-9])?$/", $str);
}
function is_chinese($str){
检验是否是中文
return ereg("^[".chr(0xa1)."-".chr(0xff)."]+$",$str);
}
function is_english($str){
//检验是否是英文
return preg_match("/^[A-Za-z]+$/", $str);
}
function is_mobile($str){
//检验是否是手机
return preg_match("/^((\(\d{3}\))|(\d{3}\-))?13\d{9}$/", $str);
}
function is_phone($str){
//建云那是否是电话
return preg_match("/^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/",
$str);
}
function is_safe($str){
return (preg_match("/^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.
{0,5})$|\s/", $str) != 0);
}
}
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
MySQL 导出数据为csv格式的方法
python 中的int()函数怎么用
session 加入mysql库的方法
![](https://img.aspxhome.com/file/2023/9/118439_0s.png)
MySQL选错索引的原因以及解决方案
![](https://img.aspxhome.com/file/2023/8/102388_0s.png)
如何实现My SQL中的用户的管理问题
Python绘制三角函数图(sin\\cos\\tan)并标注特定范围的例子
![](https://img.aspxhome.com/file/2023/5/97635_0s.jpg)
Python 日期的转换及计算的具体使用详解
pyqt5实现按钮添加背景图片以及背景图片的切换方法
![](https://img.aspxhome.com/file/2023/5/98875_0s.jpg)
如何提高网页的维护效率
Python中 CSV格式清洗与转换的实例代码
GO语言操作Elasticsearch示例分享
Python异步处理返回进度——使用Flask实现进度条
![](https://img.aspxhome.com/file/2023/7/102947_0s.gif)
Apifox Echo学习curl httpie 命令使用详解
![](https://img.aspxhome.com/file/2023/1/127201_0s.png)
如何优化JavaScript脚本的性能
Python实现把xml或xsl转换为html格式
python中的load、loads实现反序列化示列
在数据库中自动生成编号的实现方法分享
人民币的符号的正确表示法?一杠?两杠?¥还是¥呢?
Go语言使用钉钉机器人推送消息的实现示例
![](https://img.aspxhome.com/file/2023/4/127064_0s.png)
微信小程序之数据缓存的实例详解
![](https://img.aspxhome.com/file/2023/8/136128_0s.png)