url<E> static method

Rule<String, E> url<E>({
  1. required E error,
})

Validates that the string is a valid URL.

StringRules.url(error: 'Invalid URL')

Implementation

static Rule<String, E> url<E>({required E error}) => PredicateRule(
      predicate: (value) {
        try {
          final uri = Uri.parse(value);
          return uri.hasScheme && uri.hasAuthority;
        } catch (_) {
          return false;
        }
      },
      error: error,
    );