Swiftpack.co -  ssb-swift/StringIsValidDomain as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Validate domain names in Swift
.package(url: "https://github.com/ssb-swift/StringIsValidDomain.git", from: "1.0.1")


Validate domain names in Swift | is-valid-domain




Add the following to the Package.swift dependencies:

.package(url: "https://github.com/ssb-swift/StringIsValidDomain", from: "1.0.0")

Or add the package in Xcode.


import StringIsValidDomain

"example.com".isValidDomain())                                          // true
"foo.example.com".isValidDomain())                                      // true
"bar.foo.example.com".isValidDomain())                                  // true
"exa-mple.co.uk".isValidDomain())                                       // true
"xn--80ak6aa92e.com".isValidDomain())                                   // true
"_dnslink.ipfs.io".isValidDomain())                                     // true
"exa_mple.com".isValidDomain())                                         // false
"-example.co.uk".isValidDomain())                                       // false
"example".isValidDomain())                                              // false
"ex*mple.com".isValidDomain())                                          // false
"*.example.com".isValidDomain())                                        // false
"*.com".isValidDomain())                                                // false

"foo.example.com".isValidDomain([.subdomain: true])                     // true
"foo.example.com".isValidDomain([.subdomain: false])                    // false
"*.example.com".isValidDomain([.wildcard: false])                       // false
"*.example.com".isValidDomain([.wildcard: true])                        // true
"*.example.com".isValidDomain([.subdomain: false, .wildcard: true])     // false
"はじめよう.みんな".isValidDomain()                                         // false
"はじめよう.みんな".isValidDomain([.allowUnicode: true])                    // true

View more examples.



This project uses [swift-format][swift-format] for automatic code formatting as a pre-commit hook; Use the following instructions to set up swift-format for your environment:

Install swift-format

cd <repository-location>
git clone -b swift-5.4-branch https://github.com/apple/swift-format.git
cd swift-format
swift build

Add switf-format to your PATH

export PATH=$PATH:~/<repository-location>/swift-format/.build/x86_64-apple-macosx/debug

Don't forget to reload your Terminal configuration.

Create the Git hook

  • Create the pre-commit file in the project's .git/hooks directory.
touch .git/hooks/pre-commit
  • Give the file execution rights:
sudo chmod +x .git/hooks/pre-commit
  • Add the following script to the pre-commit file and save the changes:
swift-format --version 1>/dev/null 2>&1
if [ $? -eq 0 ]
    git diff --diff-filter=d --staged --name-only | grep -e '\(.*\).swift$' | while read line; do
        swift-format -i "${line}";
        git add "$line";

Now, every time you commit new changes in the project, swift-format will automatically format them before committing them.


  • Q: Why is trailing dot . in domain names verified as true?

    • A: Fully qualified domain names allow the trailing dot which represents the root zone. More info here and here.


Stars: 0
Last commit: 5 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.


Release Notes

Release v1.0.1
5 weeks ago
  • Parse labels to String on initialization

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API