Email regular expression and URL regular expression

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags .url address array content echo email expression get

email regular expressions and url regular expressions Here are two regular and very useful email regular expressions and URL regular expression validation, regular expressions on email can get all the email addresses in the content, and url The same is true of the address, url can be extracted from the contents of all http URL to extract oh.
* /

$ str_arr = array (
"mymail@jzread.com",
"my_mail@jzread.com",
"my-mail@jzread.com",
"my.mail@site.com.cn",
"mymail@site.com.ccoomm",
"mymail@site.cn",
"mymail @@@ lsite.com",
"mymail @ site",
"mymail@jzread.com",
"my2007@jzread.com",
"163mail_for-me777@jzread.com",
);

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

foreach ($ str_arr as $ str)
{
echo "string '$ str': yes";
if (preg_match ($ patt_email, $ str))
{
echo "<b> legal email format </ b>";
echo "<br>";
echo "<br>";
}
else
{
Echo "illegal email format";
echo "<br>";
echo "<br>";
}
}

// 17, url regular expression.

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

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

foreach ($ str_arr as $ str)
{
echo "string '$ str': yes";
if (preg_match ($ patt_url, $ str))
{
echo "<b> Legal url format </ b>";
echo "<br>";
echo "<br>";
}
else
{
echo "illegal url format";
echo "<br>";
echo "<br>";
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.