How long can a TLD possibly be?

前端 未结 7 1926
忘了有多久
忘了有多久 2020-11-28 07:03

I\'m working on an email validation regex in PHP and I need to know how long the TLD could possibly be and still be valid. I did a few searches but couldn\'t find much infor

7条回答
  •  粉色の甜心
    2020-11-28 07:43

    The longest TLD currently in existence is 24 characters long, and subject to change. The maximum TLD length specified by RFC 1034 is 63 octets.

    To get the length of the longest existing TLD:

    wget -qO - http://data.iana.org/TLD/tlds-alpha-by-domain.txt | tail -n+2 | wc -L
    

    Here's what that command does:

    1. Get the latest list of actual existing TLDs from IANA
    2. Strip the first line, which is a long-ish comment
    3. Launch wc to count the longest line

    Alternative using curl thanks to Stefan:

    curl -s http://data.iana.org/TLD/tlds-alpha-by-domain.txt | tail -n+2 | wc -L
    

提交回复
热议问题