开发者

How to validate hostname in Perl?

开发者 https://www.devze.com 2023-01-03 11:49 出处:网络
I need to come up with a regular expression to validate hostname against RFC-1123 and RFC-952. Right now I\'m using this:

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](?:(?开发者_C百科:[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


Regexp::Common contains a regex that matches against RFC-1035, is this good enough?


I found Data::Validate::Domain on CPAN.

I have not tried this, but it looks promising (has positive reviews etc.).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号