1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00
comunicmobile/lib/utils/input_utils.dart
2019-05-01 10:21:26 +02:00

30 lines
871 B
Dart

/// Input utilities
///
/// @author Pierre HUBERT
/// Check out whether a given email address is valid or not
///
/// Taken from https://medium.com/@nitishk72/form-validation-in-flutter-d762fbc9212c
bool validateEmail(String value) {
Pattern pattern =
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
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;
}
}