Regular Expressions 101

Community Patterns

1...45678...902

Community Library Entry

4

Regular Expression
PCRE (PHP <7.3)

/
^(?:_?(?>[a-z\d][a-z\d-]{0,61}[a-z\d]|[a-z\d])\.)*(?:_?(?>[a-z\d][a-z\d-]{0,61}[a-z\d]|[a-z\d]))\.?$
/
i

Description

Validates that a DNS hostname is well-formed only. You will still need to check that the overall length of the hostname, including the implied trailing "." (if not present), does not exceed 255 bytes.

Submitted by Jeff Walter - 9 years ago