2014-06-15 01:47:15 +02:00
|
|
|
<?php
|
|
|
|
|
2014-09-23 22:47:55 +02:00
|
|
|
namespace Amp\Dns;
|
2014-06-15 01:47:15 +02:00
|
|
|
|
2014-09-23 22:47:55 +02:00
|
|
|
class NameValidator {
|
2014-06-15 01:47:15 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2014-09-23 22:47:55 +02:00
|
|
|
public function validate($name) {
|
2014-06-15 01:47:15 +02:00
|
|
|
return strlen($name) <= 253 && preg_match($this->validatePattern, $name);
|
|
|
|
}
|
|
|
|
}
|