url static method

Validator url({
  1. String? message,
})

URL / Website validator

Implementation

static Validator url({String? message}) {
  final reg = RegExp(
    r'^(https?:\/\/)?' // protocol
    r'([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}' // domain
    r'(\/[^\s]*)?$', // path
    caseSensitive: false,
  );
  return (String? value) {
    if (value == null || value.trim().isEmpty) return null; // optional
    if (!reg.hasMatch(value.trim())) {
      return message ?? 'Invalid URL';
    }
    return null;
  };
}