推荐

php判断域名格式是否正确

2014-10-16 08:29
<?php
//url validation
$url = 'teSTgjhgj.co.uk';
if (preg_match ("/^[a-z0-9][a-z0-9-]+[a-z0-9](.[a-z]{2,4})+$/i", $url)) {
    print "$url url OK.";
} else {
    print "$url url not valid!";
}
?>

<?php
//domain validation
$domain = 'teSTgjhgj';
if (preg_match ("/^[a-z0-9][a-z0-9-]+[a-z0-9]$/i", $domain)) {
    print "$domain Domain OK.";
} else {
    print "$domain Domain not valid!";
}
?>
^