# User Preference 'Website' does not allow new TLDs

**URL:** <https://meta.discourse.org/t/user-preference-website-does-not-allow-new-tlds/49931>\
**Category:** Bug\
**Created:** [9 Settembre 2016, 1:08pm UTC](https://meta.discourse.org/t/user-preference-website-does-not-allow-new-tlds/49931 "2016-09-09T13:08:57Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![elijah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elijah/32/104055_2.png) [@elijah](https://meta.discourse.org/u/elijah)\
**Post date:** [9 Settembre 2016, 8:28pm UTC](https://meta.discourse.org/t/user-preference-website-does-not-allow-new-tlds/49931/3 "2016-09-09T20:28:57Z")

</div>

> [@cpradio](#):
>
> Changing the 2,10 to 2, would permit any length, but not sure if that would be the right modification for this.

I have many questions about that RE.

Here’s a fragment to match a DNS label (other than top-level):

`/[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?/i`

What it is doing:

- a label must start with a letter or number: `[a-z0-9]`
- you can have letters, numbers and hyphens in the middle: `[a-z0-9-]{0,61}`
  - double hyphens _are_ allowed
  - a label can be up to 63 characters long

- a label must end with a letter or number: `[a-z0-9]`

The rules for a TLD are the same, except that all numeric is not allowed.

No number in first position (one character label okay): `/([a-z]([a-z0-9-]{0,61}[a-z0-9])?)/i`  
No number in last position (two character minimum): `/[a-z0-9][a-z0-9-]{0,61}[a-z]/i`  
At least one letter in middle part (hacky for making RE readable): `/[a-z0-9][a-z0-9-]{1,30}[a-z]([a-z0-9-]{0,30}[a-z0-9])?/i`

> **hacky**
>
> The hacky one could be rewritten to all compliant strings, but it is ugly to enforce a letter somewhere while also enforcing a length restriction. There will be a ton of `|`s in the proper answer.

Combined hostname RE: `(labelpart\.)+(tldpart1|tldpart2|tldpart3)` :

```plaintext
/([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+(([a-z]([a-z0-9-]{0,61}[a-z0-9])?)|[a-z0-9][a-z0-9-]{0,61}[a-z]|[a-z0-9][a-z0-9-]{1,30}[a-z]([a-z0-9-]{0,30}[a-z0-9])?/i

```

And final combined WEBSITE\_REGEXP:

```ruby
WEBSITE_REGEXP = /(^$)|(^(http|https):\/\/([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+(([a-z]([a-z0-9-]{0,61}[a-z0-9])?)|[a-z0-9][a-z0-9-]{0,61}[a-z]|[a-z0-9][a-z0-9-]{1,30}[a-z]([a-z0-9-]{0,30}[a-z0-9])?\/.*)?$)/ix

```

(The syntax highlighter gets confused by the “Combined” line.)

Does /x to ruby mean the same as /x to perl? If so, in-line comments and a reformat should be added.

---

_[View the full topic](https://meta.discourse.org/t/user-preference-website-does-not-allow-new-tlds/49931)._
