Files
MrbWebLibre/app/lib/utils/form_validators.dart
T
2025-03-03 15:15:05 +01:00

31 lines
704 B
Dart

import 'package:lensai/extensions/nullable.dart';
import 'package:lensai/utils/uri_parser.dart' as uri_parser;
String? validateUrl(
String? value, {
bool requireAuthority = true,
bool eagerParsing = true,
bool onlyHttpProtocol = false,
bool required = true,
}) {
if (value.isEmpty) {
if (required) {
return 'URL must be provided';
} else {
return null;
}
}
if (uri_parser.tryParseUrl(value, eagerParsing: eagerParsing)
case final Uri url) {
if (!requireAuthority || url.authority.isNotEmpty) {
if (!onlyHttpProtocol ||
(url.isScheme('https') || url.isScheme('http'))) {
return null;
}
}
}
return 'Inavlid URL';
}