1
0
mirror of https://github.com/danog/dns.git synced 2024-11-27 04:24:48 +01:00
dns/lib/NameValidator.php
Niklas Keller 0ac694a5ee Match also subdomains with only one character
Example: m.example.com
2015-02-09 12:27:04 +01:00

23 lines
495 B
PHP

<?php
namespace Amp\Dns;
class NameValidator {
/**
* Regex for validating domain name format
*
* @var string
*/
private $validatePattern = '/^(?:[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9]){0,1})(?:\.[a-z0-9][a-z0-9\-]{0,61}[a-z0-9])*$/i';
/**
* Check that a name is valid
*
* @param string $name
* @return bool
*/
public function validate($name) {
return strlen($name) <= 253 && preg_match($this->validatePattern, $name);
}
}