Skip to content

feat: Add isValidDomain helper for validation#55

Merged
pranavrajs merged 1 commit into
mainfrom
feat/valid-domain
Jul 30, 2025
Merged

feat: Add isValidDomain helper for validation#55
pranavrajs merged 1 commit into
mainfrom
feat/valid-domain

Conversation

@iamsivin

@iamsivin iamsivin commented Jul 30, 2025

Copy link
Copy Markdown
Member

This PR adds a new helper isValidDomain

Returns true for:

  • Empty string (treated as valid).
  • Standard domains: google.com, example.org, test.net.
  • Subdomains (any depth): www.google.com, api.example.org, deep.nested.subdomain.com.
  • Hyphens in the middle: my-site.com.
  • Multi-part TLDs: example.co.uk, test-domain.co.uk.
  • Labels with digits: 123domain.org.
  • Internationalized (Unicode) domains: 测试.网络, пример.рф.
  • Length limit: total domain length ≤ 253 chars; each label 1–63 chars.

Returns false for:

  • Single-label hosts: localhost.
  • Invalid characters: example.com!, test@domain.com, spaces, underscores, etc.
  • Dot misuse: example..com, ..example.com, example.com...
  • Bad hyphen placement: labels starting/ending with -, e.g., -example-.com.
  • Too long overall (e.g., 250+.com pushing length >253).
  • IP addresses: 192.168.1.1, 127.0.0.1.
  • URLs or paths: http://example.com, https://example.com, example.com/path.
  • Non-strings / blanks: null, undefined, numbers, objects, arrays, or just spaces.
  • Double hyphens anywhere (disallowed by the regex), which also blocks punycode-style xn--… labels.

@github-actions

Copy link
Copy Markdown

size-limit report 📦

Path Size
dist/utils.cjs.production.min.js 10.93 KB (+47.97% 🔺)
dist/utils.esm.js 10.36 KB (+52.46% 🔺)

@pranavrajs pranavrajs merged commit 75860ac into main Jul 30, 2025
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants