Regular Expression for validating DNS label ( host name)

后端 未结 6 1314
长发绾君心
长发绾君心 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:35

    Javascript regex based on Marks answer:

    pattern = /^(?![0-9]+$)(?!.*-$)(?!-)[a-zA-Z0-9-]{1,63}$/g;
    

提交回复
热议问题