Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Function to Validate Domain in URLs #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

r0227n
Copy link

@r0227n r0227n commented Jan 27, 2024

Overview

This Pull Request introduces a new utility function, verifyDomain, designed to validate the domain within a given URL. This function ensures that the URL not only conforms to the standard URL format but also checks that the domain part of the URL is valid as per the typical domain naming conventions.

Implementation Details

The function isValidDomain takes a string input, which is expected to be a URL.
It first parses the URL using Dart's Uri.parse method.
Validates that the URL's scheme is either http or https.
Applies a regular expression to validate the domain format. This regex checks for common domain naming patterns and is designed to be robust enough to handle a wide variety of valid domains.
The function returns a boolean value indicating the validity of the domain.

Error Handling

The function is wrapped in a try-catch block to gracefully handle any exceptions that might occur during the URL parsing process, returning false in case of an error.

Use Case

This function is particularly useful in scenarios where validating the integrity of a URL is crucial, such as when processing web links, ensuring valid input in forms, or dealing with external URLs in a secure manner.

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.

1 participant