Regular expression for validating hostname
For help clarifying this question so that it can be reopened, visit the help center.(Not a downvoter) What are you actually trying to accomplish??is a syntaxticly invalid NTP server hostname.) The reason I want to make this basic validation is because I am building a Web app to configure a server.The app presents the user with a form, for which one of the fields is .
A man page on hostname validation has been available since 1.0.2. The following is from Hostname validation and shows how you could use Open SSL's built-in hostname validation.
List item Your question is wrongly phrased: a host name has nothing to do with a DNS label for two reasons: a host name can be a Fully Qualified Domain Name and the syntax for host names is much more restrictive than the syntax for domain names. For most people host name is the part before the domain. A more readable and portable approach is to require a string to match both of these POSIX ERE's: Those should be easy to use in any standard-compatible ERE implementation.
However, a full hostname may not be only numeric values because then it is an IP address.tests = [ ('01010', False), ('abc', True), ('A0c', True), ('A0c-', False), ('-A0c', False), ('A-0c', True), ('o123456701234567012345670123456701234567012345670123456701234567', False), ('o12345670123456701234567012345670123456701234567012345670123456', True), ('', True), ('a', True), ('0--0', True), ] import re regex = re.compile('^(?! However, for the whole domain name to be all numeric is in practice disallowed, since TLDs are not all numeric, and it is expected that one can distinguish syntactically between IPs and domain names.
The first character must be an alpha character [Relaxed in RFC 1123] .
The last character must not be a minus sign or period.
Search for regular expression for validating hostname:
The first line handles all of the rules other than the ban on all-digits, the second kills those.