urlAsync<T> static method
Asynchronously validates URLs with comprehensive format and domain checking.
Provides advanced URL validation including format verification, scheme restrictions, domain whitelisting, and optional DNS lookup. Return type is generic:
String: Returns validation messagebool: Returns true/false for validityUrlValidationResult: Returns complete result with parsed URL data
Parameters:
url: The URL string to validateallowRelative: Whether to allow relative URLs (default: false)allowedSchemes: List of allowed URL schemesallowedDomains: List of allowed domainsnormalize: Whether to normalize the URL (default: true)checkDomainExists: Whether to perform DNS lookup (default: false, can be slow) Validates a URL with optional DNS verification and format checks.
Parameters:
url: The URL to validateallowRelative: Whether to allow relative URLs (default: false)allowedSchemes: List of allowed URL schemes (e.g.'http', 'https')allowedDomains: List of allowed domains (e.g.'example.com')normalize: Whether to normalize the URL (default: true)checkDomainExists: Whether to verify domain exists via DNS (default: false)
Generic type T can be:
String: Returns error message or 'URL is valid'bool: Returns true/falseUrlValidationResult: Returns detailed validation result object
Example:
// Simple boolean check
final isValid = await SahihValidator.urlAsync<bool>('https://example.com');
// Detailed result
final result = await SahihValidator.urlAsync<UrlValidationResult>(
'https://example.com/path',
allowedDomains: ['example.com']
);
Implementation
static Future<T> urlAsync<T>(
String url, {
bool allowRelative = false,
List<String>? allowedSchemes,
List<String>? allowedDomains,
bool normalize = true,
bool checkDomainExists = false,
}) async {
return await isValidUrlAsync<T>(
url,
allowRelative: allowRelative,
allowedSchemes: allowedSchemes,
allowedDomains: allowedDomains,
normalize: normalize,
checkDomainExists: checkDomainExists,
);
}