How to validate hostname in perl?
Posted
by embedded
on Stack Overflow
See other posts from Stack Overflow
or by embedded
Published on 2010-06-10T07:45:38Z
Indexed on
2010/06/10
7:52 UTC
Read the original article
Hit count: 282
Hi,
I need to come up with a regular expression to validate hostname against RFC-1123 and RFC-952.
Right now I'm using this:
^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|\b-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|\b-){0,61}[0-9A-Za-z])?)*\.?$/
but this does not do the trick since it does not catch a. as invalid hostname.
How do I enhance the reg expression to comply with those RFCs?
Thanks
© Stack Overflow or respective owner