Regular Expression for validating DNS label ( host name)

后端 未结 6 1312
长发绾君心
长发绾君心 2020-12-03 21:11

I would like to validate a hostname using only regualr expression.

Host Names (or \'labels\' in DNS jargon) were traditionally defined by RFC 952 and RFC 1123 and m

6条回答
  •  盖世英雄少女心
    2020-12-03 21:37

    While the accepted answer is correct, RFC2181 also states under Section 11, "Name Syntax":

    The DNS itself places only one restriction on the particular labels that can be used to identify resource records. That one restriction relates to the length of the label and the full name. [...] Implementations of the DNS protocols must not place any restrictions on the labels that can be used. In particular, DNS servers must not refuse to serve a zone because it contains labels that might not be acceptable to some DNS client programs.

    This in turn means other characters such as underscores should be allowed.

提交回复
热议问题