一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Email正则表达式与URL正则表达式

时间:2022-06-24 21:45:44 编辑:袖梨 来源:一聚教程网

 代码如下 复制代码

 $str_arr = array(
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"mymail@@@lsite.com",
"mymail@site",
"[email protected]",
"[email protected]",
"[email protected]",
);

$patt_email = "/^[_a-za-z0-9-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/";

foreach ($str_arr as $str)
{
    echo "字符串'$str':是";
    if (preg_match($patt_email, $str))
    {
        echo "合法的email格式";
        echo "
";
        echo "
";
    }
    else
    {
        echo "不合法的email格式";
        echo "
";
        echo "
";
    }
}
 

// 17、url正则表达式。
 

 代码如下 复制代码

$str_arr = array(
"http://www.111com.net",
"www.111com.net",
"http://www.111com.net/abc/123.html",
"//111com.net",
":www.111com.net"
);

$patt_url = "/^(http://)?[a-za-z0-9]+(.[a-za-z0-9]+)*.+$/";

foreach ($str_arr as $str)
{
    echo "字符串'$str':是";
    if (preg_match($patt_url, $str))
    {
        echo "合法的url格式";
        echo "
";
        echo "
";
    }
    else
    {
        echo "不合法的url格式";
        echo "
";
        echo "
";
    }
}

热门栏目