URL Validation
import 'package:luthor/luthor.dart';
void main() { final validator = l.string().url(); print(validator.validateValue('https://dart.dev')); // Success print(validator.validateValue('not a url')); // Error
// With allowed schemes final httpsOnly = l.string().url(allowedSchemes: ['https']); print(httpsOnly.validateValue('https://dart.dev')); // Success print(httpsOnly.validateValue('http://dart.dev')); // Error}
The URL validator ensures that a string is a valid URL with a scheme and host. By default, it accepts any valid URL scheme, but you can restrict allowed schemes using the allowedSchemes
parameter.
A URL is considered valid if:
- It has a valid scheme (e.g., ‘http’, ‘https’, ‘ftp’, etc.)
- It has a valid host
- It contains no whitespace characters
- The scheme matches one of the
allowedSchemes
if specified
You can also provide a custom error message:
l.string().url(message: 'Please enter a valid website URL');