function strLength($string){
$array = preg_split('/(?<!^)(?!$)/u',$string);
return count($array);
}
固话
$result = preg_match("/^(0(10|21|22|23|[1-9][0-9]{2})(-|))?[0-9]{7,8}$/", $phone,$match);
移动电话
$result = preg_match("/^((\(\d{3}\))|(\d{3}\-))?1\d{10}$/", $phone,$match);
邮箱
strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-]+(\.\w+)+$/", $email)
URL地址
preg_match("/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"])*$/", $str);
PHP求字符串的长度 部分正则表达式
最新推荐文章于 2021-04-04 18:11:13 发布
本文提供了使用PHP正则表达式验证固定电话、移动电话、电子邮箱及URL地址的有效性的示例代码。通过这些代码片段,读者可以了解如何利用正则表达式进行基本的数据格式验证。
658

被折叠的 条评论
为什么被折叠?



