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
|
|
|
|
*/
|
2014-10-02 17:41:33 +02:00
|
|
|
private $validatePattern = '/^(?:[a-z0-9][a-z0-9\-]{0,61}[a-z0-9])(?:\.[a-z0-9][a-z0-9\-]{0,61}[a-z0-9])*$/i';
|
2014-06-15 01:47:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|