e-mail regular expression and URL regular expression _php tutorial

Source: Internet
Author: User
Email regular expressions and URL regular expressions There are two regular expressions about email regular expression and URL regular expression validation, which is very useful, the regular expression about email can get all the mailbox address in the content, and the URL address is the same, You can save and extract all HTTP start URL addresses in the content.

e-mail regular expressions and URL regular expressions
Here are two kinds of regular expressions about email and URL regular expression validation, it is very practical, the regular expression about email can get all the mailbox address in the content, and the URL address is the same, you can all the content in the beginning of the HTTP URL to save extract Oh.
*/

$str _arr = Array (
"Mymail@bkjia.c0m",
"My_mail@bkjia.c0m",
"My-mail@bkjia.c0m",
"My.mail@site.com.cn",
"Mymail@site.com.ccoomm",
"Mymail@site.cn",
"mymail@@ zzfcthotfixz. com",
"Mymail@site",
"Mymail@bkjia.c0m",
"My2007@bkjia.c0m",
"163mail_for-me777@bkjia.c0m",
);

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

foreach ($str _arr as $STR)
{
echo "String ' $str ': yes";
if (Preg_match ($patt _email, $STR))
{
echo " Legal email format ";
echo "
";
echo "
";
}
Else
{
echo "illegal email format";
echo "
";
echo "
";
}
}

17, the URL regular expression.

$str _arr = Array (
"Http://www.bKjia.c0m",
"Www.bKjia.c0m",
"Http://www.bKjia.c0m/abc/123.html",
"//bkjia.c0m",
": www.bKjia.c0m"
);

$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 " valid URL format ";
echo "
";
echo "
";
}
Else
{
echo "Illegal URL format";
echo "
";
echo "
";
}
}

http://www.bkjia.com/PHPjc/631362.html www.bkjia.com true http://www.bkjia.com/PHPjc/631362.html techarticle email regular expressions and URL regular expressions There are two regular expressions about email regular expression and URL regular expression validation, very practical, the regular expression about e-mail can be put inside ...

  • 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.