这里提供两种关于Email正则表达式与URL正则表达式验证的正则,非常的实用,关于email的正则表达式可以把内容中的所有邮箱地址获取出来,而url地址正则也一样,可以把内容中所有http开头url地址保存提取来哦。
Email正则表达式:
- $str_arr = array(
- "mymail@Vevb.com",
- "my_mail@Vevb.com",
- "my-mail@Vevb.com",
- "my.mail@site.com.cn",
- "mymail@site.com.com",
- "mymail@site.cn",
- "mymail@@@lsite.com",
- "mymail@site",
- "mymail@Vevb.com",
- "my2007@Vevb.com",
- "163mail_for-me777@Vevb.com",
- );
- $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 "
";- }
- }
url正则表达式:
- $str_arr = array(
- "http://www.Vevb.com",
- "www.Vevb.com",
- "http://www.Vevb.com/abc/123.html",
- "//Vevb.com",
- ":www.Vevb.com"
- );
- $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 "
";- }
- }
新闻热点
疑难解答