php 常用 小知识点

时间:2023-03-08 16:05:45

PHP 邮箱正则表达式代码如下:

/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i

  示例:

<?php
$mail = 'abcdedf@abc12.com';
$pattern = '/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i';
preg_match($pattern, $mail, $matches);
var_dump($matches);
?>

手机号码正则表达式

/^(1(([35][0-9])|(47)|[8][0126789]))\d{8}$/

  示例:

$text = '15812345678';
$search ='/^(1(([35][0-9])|(47)|[8][0126789]))\d{8}$/';
if(preg_match($search,$text)) {
echo '手机完全符合';
}