# "Host is invalid" error when TLD is longer than 7 characters

**URL:** <https://meta.discourse.org/t/host-is-invalid-error-when-tld-is-longer-than-7-characters/46081>\
**Category:** Bug\
**Created:** [June 20, 2016, 7:13pm UTC](https://meta.discourse.org/t/host-is-invalid-error-when-tld-is-longer-than-7-characters/46081 "2016-06-20T19:13:23Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![flimm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/flimm/32/121704_2.png) [@flimm](https://meta.discourse.org/u/flimm)\
**Post date:** [June 20, 2016, 7:13pm UTC](https://meta.discourse.org/t/host-is-invalid-error-when-tld-is-longer-than-7-characters/46081/1 "2016-06-20T19:13:23Z")

</div>

When setting the allowed hosts for embedding, I get this error: `Host is invalid`.

This is because it is not passing this regex in the source code, line 26 in the source code of `embeddable_host.rb`: [Link](https://github.com/discourse/discourse/blob/648bcb6432ee1fbca0fc9d45c25c3d114f2a0892/app/models/embeddable_host.rb#L26)

```
def host_must_be_valid
  if host !~ /\A[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,7}(:[0-9]{1,5})?(\/.*)?\Z/i &&
     host !~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/
    errors.add(:host, I18n.t('errors.messages.invalid'))
  end
end

```

This regex only passes if the TLD is seven characters long or fewer. There are many TLDs that are longer than that nowadays, for instance:

- .cancerresearch
- .xn–y9a3aq
- .consulting

The fix should be fairly easy.

---

_[View the full topic](https://meta.discourse.org/t/host-is-invalid-error-when-tld-is-longer-than-7-characters/46081)._
