1
0
mirror of https://github.com/danog/dns.git synced 2024-12-02 09:27:55 +01:00
dns/lib/Addr/NameValidator.php
Chris Wright d5b5192ba3 Finished initial implementation
zOMG too many things to document
2014-06-15 00:47:15 +01:00

25 lines
481 B
PHP

<?php
namespace Addr;
class NameValidator
{
/**
* Regex for validating domain name format
*
* @var string
*/
private $validatePattern = '/^(?:[a-z][a-z0-9\-]{0,61}[a-z0-9])(?:\.[a-z][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);
}
}