D
D
Dmitry Sidorov2013-04-22 18:30:35
Domain name market
Dmitry Sidorov, 2013-04-22 18:30:35

Regular expression for subdomain validation

I searched the Internet for ready-made regular expressions to check the correctness of entering a subdomain.
A lot of them. But something was bothering me. I decided to dig further and found this document: www.ietf.org/rfc/rfc1035 .
I created the following expression for it:

[A-Za-z](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?

It turns out that the first character in a domain name cannot be a number. If so, why is the entire internet teeming with misinformation? Or maybe the specified RFC is no longer valid? Tell the current one.

Thank you!

UPD: In total, the correct expression is:
[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xaker1, 2013-04-22
@Doomsday_nxt

Perhaps in itself this restriction was, but one of the subsequent RFCs was canceled.

RFC 1035 Updated by RFC 1101 RFC 1183 RFC 1348 RFC 1876 RFC 1982 RFC 1995 RFC 1996 RFC 2065 RFC 2136 RFC 2181 3425, RFC 3658, RFC 4033, RFC 4034, RFC 4035, RFC 4343, RFC 5936, RFC 5966, RFC 6604.

S
sHaggY_caT, 2013-04-22
@sHaggY_caT

Please don't take it as an advertisement! Just the first domain that I found that does not fall under your regular season:
2000.ru/
Perfume store

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question