5 kyu

Domain name validator

332 of 571Disassembler0

Description:

In this kata you have to create a domain name validator mostly compliant with RFC 1035, RFC 1123, and RFC 2181

For purposes of this kata, following rules apply:

  • Domain name may contain subdomains (levels), hierarchically separated by . (period) character
  • Domain name must not contain more than 127 levels, including top level (TLD)
  • Domain name must not be longer than 253 characters (RFC specifies 255, but 2 characters are reserved for trailing dot and null character for root level)
  • Level names must be composed out of lowercase and uppercase ASCII letters, digits and - (minus sign) character
  • Level names must not start or end with - (minus sign) character
  • Level names must not be longer than 63 characters
  • Top level (TLD) must not be fully numerical

Additionally, in this kata

  • Domain name must contain at least one subdomain (level) apart from TLD
  • Top level validation must be naive - ie. TLDs nonexistent in IANA register are still considered valid as long as they adhere to the rules given above.

The validation function accepts string with the full domain name and returns boolean value indicating whether the domain name is valid or not.

Examples:

validate('codewars') == False
validate('g.co') == True
validate('codewars.com') == True
validate('CODEWARS.COM') == True
validate('sub.codewars.com') == True
validate('codewars.com-') == False
validate('.codewars.com') == False
validate('example@codewars.com') == False
validate('127.0.0.1') == False
Regular Expressions
Strings
Fundamentals

Stats:

CreatedFeb 2, 2017
PublishedFeb 2, 2017
Warriors Trained2406
Total Skips655
Total Code Submissions12791
Total Times Completed571
Python Completions332
PHP Completions111
C# Completions138
Total Stars100
% of votes with a positive feedback rating91% of 133
Total "Very Satisfied" Votes109
Total "Somewhat Satisfied" Votes23
Total "Not Satisfied" Votes1
Total Rank Assessments11
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Disassembler0 Avatar
  • donaldsebleung Avatar
  • kazk Avatar
  • hobovsky Avatar
Ad