1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 08:15:16 +00:00

Parse links

This commit is contained in:
2019-05-01 10:21:26 +02:00
parent e7c34e6e71
commit fcc8c2faa4
5 changed files with 102 additions and 2 deletions

View File

@ -11,3 +11,19 @@ bool validateEmail(String value) {
RegExp regex = new RegExp(pattern);
return regex.hasMatch(value);
}
/// Check out whether a given string is a valid URL or not
bool validateUrl(String url) {
//Initial check
if (!url.startsWith("http://") && !url.startsWith("https://")) return false;
try {
final uri = Uri.parse(url);
return uri.hasScheme &&
uri.hasAuthority &&
uri.port != 0 &&
uri.path.length != 0;
} catch (e) {
return false;
}
}