- preg_match: documentation ( source)
<?php
$domain_name = "ăîăîîas.idn.icann.org64";
$domain_name = idn_to_ascii($domain_name);
function is_valid_domain_name($domain_name) {
return (preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $domain_name) //valid chars check
&& preg_match("/^.{1,253}$/", $domain_name) //overall length check
&& preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name) ); //length of each label
}
echo is_valid_domain_name($domain_name) ? "Domain is valid." : "Domain is not valid.";
?>