mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
5d3af16aaf
- moving all phpunit tests into tests/php - moving all extensions from _config.php into config.yml and removing obsolete _config.php - moving GridFieldSubsiteDetailForm_ItemRequest into own file (cherry picked from commit ee02828)
51 lines
1.0 KiB
PHP
51 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\Subsites\Forms;
|
|
|
|
use SilverStripe\Forms\TextField;
|
|
|
|
/**
|
|
* A text field that accepts only valid domain names, but allows the wildcard (*) character
|
|
*/
|
|
class WildcardDomainField extends TextField
|
|
{
|
|
|
|
/**
|
|
* Validate this field as a valid hostname
|
|
*
|
|
* @param Validator $validator
|
|
* @return bool
|
|
*/
|
|
public function validate($validator)
|
|
{
|
|
if ($this->checkHostname($this->Value())) {
|
|
return true;
|
|
}
|
|
|
|
$validator->validationError(
|
|
$this->getName(),
|
|
_t("DomainNameField.INVALID_DOMAIN", "Invalid domain name"),
|
|
"validation"
|
|
);
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Check if the given hostname is valid.
|
|
*
|
|
* @param string $hostname
|
|
* @return bool True if this hostname is valid
|
|
*/
|
|
public function checkHostname($hostname)
|
|
{
|
|
return (bool)preg_match('/^([a-z0-9\*]+[\-\.])*([a-z0-9\*]+)$/', $hostname);
|
|
}
|
|
|
|
public function Type()
|
|
{
|
|
return 'text wildcarddomain';
|
|
}
|
|
|
|
}
|