isUrl property

bool get isUrl

Checks if the string matches a URL pattern.

Implementation

bool get isUrl {
  final urlPattern = RegExp(
    r'^(https?:\/\/)?' // optional scheme
    r'([a-zA-Z0-9.-]+(\.[a-zA-Z]{2,})+)' // domain
    r'(:\d+)?' // optional port
    r'(\/[^\s]*)?$', // optional path
    caseSensitive: false,
  );
  return urlPattern.hasMatch(this);
}