isUrl property
bool
isUrl
Checks whether the String
is a 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.isBlank) {
return false;
}
var 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!);
}