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