PHP 正则后瞻 超强匹配是否是域名,准确率99%

WBOY
Release: 2016-06-23 13:49:42
Original
1110 people have browsed it

/^([a-z0-9]+([a-z0-9-]*(?:[a-z0-9]+))?\.)?[a-z0-9]+([a-z0-9-]*(?:[a-z0-9]+))?(\.us|\.tv|\.org\.cn|\.org|\.net\.cn|\.net|\.mobi|\.me|\.la|\.info|\.hk|\.gov\.cn|\.edu|\.com\.cn|\.com|\.co\.jp|\.co|\.cn|\.cc|\.biz)$/i
Copy after login

匹配网址:

    /**     * @author      Default7 <default7>     * @description 匹配     *              t.cn 正确     *              t-.cn 错误     *              tt.cn正确     *              -t.cn 错误     *              t-t.cn 正确     *              tst-test-tst.cn 正确     *              tst--tt.cn -- 错误     *     *     *     * @param $domain     *     * @return bool     */    public function isDomain($domain)    {        return !empty($domain) && strpos($domain, '--') === false &&        preg_match('/^([a-z0-9]+([a-z0-9-]*(?:[a-z0-9]+))?\.)?[a-z0-9]+([a-z0-9-]*(?:[a-z0-9]+))?(\.us|\.tv|\.org\.cn|\.org|\.net\.cn|\.net|\.mobi|\.me|\.la|\.info|\.hk|\.gov\.cn|\.edu|\.com\.cn|\.com|\.co\.jp|\.co|\.cn|\.cc|\.biz)$/i', $domain) ? true : false;    }</default7>
Copy after login
如果有问题bug,欢迎指正 by default7#zbphp.com

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!