Add Function to Validate Domain in URLs #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.