March 19, 2020 Javier Eguiluz

Symfony provides tens of validators to check the validity of your data. That includes several validators related to computers and the Internet, such as the email validator, the IP address validator and the URL validator.

In Symfony 5.1 we've added a new one to this group: the Hostname validator, which checks that the given value is considered valid as a hostname:

1 2 3 4 5 6 7 8 9 10 11 12 // src/Entity/ServerSettings.php namespace App\Entity ; use Symfony\Component\Validator\Constraints as Assert ; class ServerSettings { /** * @Assert\Hostname(message="The server name must be a valid hostname.") */ protected $name ; }