php 正则校验是否是域名

 1 /**
 2  * @description 匹配
 3  *              t.cn 正确
 4  *              t-.cn 错误
 5  *              tt.cn正确
 6  *              -t.cn 错误
 7  *              t-t.cn 正确
 8  *              tst-test-tst.cn 正确
 9  *              tst--tt.cn -- 错误
10  *
11  *
12  *
13  * @param $domain
14  *
15  * @return bool
16  */
17 public function isDomain($domain)
18 {
19     return !empty($domain) && strpos($domain, '--') === false &&
20     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;
21 }

 

posted @ 2015-06-25 11:52  xxxxzy  阅读(5051)  评论(0编辑  收藏  举报