# User website preference is invalid with underscore

**URL:** https://meta.discourse.org/t/user-website-preference-is-invalid-with-underscore/41784
**Category:** Support
**Created:** [March 30, 2016, 6:14pm UTC](https://meta.discourse.org/t/user-website-preference-is-invalid-with-underscore/41784 "2016-03-30T18:14:39Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![dGr8LookinSparky](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dgr8lookinsparky/32/53124_2.png) [@dGr8LookinSparky](https://meta.discourse.org/u/dGr8LookinSparky)
#### Post date: [March 30, 2016, 6:14pm UTC](https://meta.discourse.org/t/user-website-preference-is-invalid-with-underscore/41784/1 "2016-03-30T18:14:39Z")

</div>

A user on our forums is getting the error “Website is invalid.” when attempting to enter his website on his profile.

The url he is using is:

```plaintext
code_man.cybnet.ch
```

Perhaps the underscore in the sub-domain is triggering the error?

The version of Discourse that we are currently using is:

```plaintext
1.5.0.beta14
```

It seems this topic might be related:

> [@URL validation for "Web Site" on user profile](https://meta.discourse.org/t/url-validation-for-web-site-on-user-profile/38864):
>
> Some validation would be nice on the “Web Site” field on user profiles. Currently, users are able to enter invalid URL’s like this one http://https://www.facebook.com/FacebookUK Side-note - I feel like “Web Site” should really be “Website”: the AP Stylebook changed 5/6 years ago Google search results for “website” - 5,450,000,000 Google search results for “web site” - 597,000,000

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 30, 2016, 6:27pm UTC](https://meta.discourse.org/t/user-website-preference-is-invalid-with-underscore/41784/2 "2016-03-30T18:27:23Z")

</div>

> [@dGr8LookinSparky](#):
>
> Perhaps the underscore in the sub-domain is triggering the error?

That’s it. Underscores are not valid characters for hostnames.

> **[Hostname](https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names)**
>
> In computer networking, a hostname (previously nodename) is a label that is assigned to a device connected to a computer network and that is used to identify the device in various forms of electronic communication, such as the World Wide Web. Hostnames may be simple names consisting of a single word or phrase, or they may be structured. Each hostname usually has at least one numeric network address associated with it for routing packets for performance and other reasons.
> Internet hostnames may h...

---

<div class="post-metadata">

### Author: ![dGr8LookinSparky](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dgr8lookinsparky/32/53124_2.png) [@dGr8LookinSparky](https://meta.discourse.org/u/dGr8LookinSparky)
#### Post date: [March 30, 2016, 7:03pm UTC](https://meta.discourse.org/t/user-website-preference-is-invalid-with-underscore/41784/3 "2016-03-30T19:03:18Z")

</div>

> [@pfaffman](#):
>
> Underscores are not valid characters for hostnames.

But the url works. Perhaps this validation could be overridden by admins if they entered the url?

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [March 30, 2016, 7:06pm UTC](https://meta.discourse.org/t/user-website-preference-is-invalid-with-underscore/41784/4 "2016-03-30T19:06:52Z")

</div>

> [@dGr8LookinSparky](#):
>
> Perhaps this validation could be overridden by admins if they entered the url?

Introduce complexity on the URL validation to let some people who wants a invalid domain on their profile? I don’t think this is a good idea.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 30, 2016, 7:40pm UTC](https://meta.discourse.org/t/user-website-preference-is-invalid-with-underscore/41784/5 "2016-03-30T19:40:39Z")

</div>

> [@dGr8LookinSparky](#):
>
> But the url works.

Well, if that were entirely true, we wouldn’t be having this conversation. 🙂

> <https://stackoverflow.com/questions/10959757/the-use-of-the-underscore-in-host-names>

[https://www.quora.com/Why-are-underscores-not-allowed-in-DNS-host-names](https://www.quora.com/Why-are-underscores-not-allowed-in-DNS-host-names)

The best solution, in my arrogant computer geek opinion, would be to point the guy to the above web sites and suggest to the guy that he’s doing it wrong and that if he wants to link to his site he should create a CNAME using a `-` instead of a `_`. (You’d probably want to find a nicer way to say that.)

---

<div class="post-metadata">

### Author: ![Ondrej\_Caletka](https://avatars.discourse-cdn.com/v4/letter/o/a9a28c/32.png) [@Ondrej\_Caletka](https://meta.discourse.org/u/Ondrej_Caletka)
#### Post date: [November 15, 2016, 1:54pm UTC](https://meta.discourse.org/t/user-website-preference-is-invalid-with-underscore/41784/6 "2016-11-15T13:54:04Z")

</div>

And what about IDNs? The regular expression validating the website url is so strict that I can’t fit in my perfectly valid URL [https://ondřej.caletka.cz](https://xn--ondej-kcb.caletka.cz)

Even using Punycode form of [https://ondřej.caletka.cz](https://xn--ondej-kcb.caletka.cz) is not accepted, even though it is perfectly valid here in this very forum post.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [December 21, 2017, 2:35pm UTC](https://meta.discourse.org/t/user-website-preference-is-invalid-with-underscore/41784/7 "2017-12-21T14:35:08Z")

</div>

Resolved by

> [@Photography Domain Invalid as Website on Profile](https://meta.discourse.org/t/photography-domain-invalid-as-website-on-profile/76319/18):
>
> OK so I had a look through the previous commits and realized that what we initially wanted to do is to [validate the format of the URL](https://meta.discourse.org/t/url-validation-for-web-site-on-user-profile/38864/5). That means that there is no need for us to care about whether the URL would return a valid HTTP response as that would require a different solution if we wanted to verify that. However, I did noticed that our UrlValidator wasn’t handling a bunch of cases properly and that has been fixed in I’ve also switched the validation for UserProfile#website to use our U…
