isUrl property

bool? isUrl

Checks whether the String is valid URL.

Example 1

String foo = 'foo.1com';
bool isUrl = foo.isUrl; // returns false

Example 2

String foo = 'google.com';
bool isUrl = foo.isUrl; // returns true

Implementation

bool? get isUrl {
  if (this == null) return null;
  if (this!.isEmpty) return false;
  final regex = RegExp(
    r'[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)',
  );
  return regex.hasMatch(this!);
}