1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-24 22:09:21 +00:00
comunicmobile/lib/utils/input_utils.dart

42 lines
1.2 KiB
Dart
Raw Permalink Normal View History

2019-04-21 09:44:07 +00:00
/// Input utilities
///
/// @author Pierre HUBERT
2020-04-30 11:32:22 +00:00
/// Check out whether a password is valid or not
2021-02-18 17:58:47 +00:00
bool legacyValidatePassword(String s) => s.length > 3;
2020-04-30 11:32:22 +00:00
2019-04-21 09:44:07 +00:00
/// 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 as String);
2019-04-21 09:44:07 +00:00
return regex.hasMatch(value);
}
2019-05-01 08:21:26 +00:00
/// 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;
}
}
2020-04-16 10:06:01 +00:00
2020-04-16 10:06:57 +00:00
/// Validate directory reference
bool validateDirectoryReference(String ref) =>
2020-04-16 10:06:01 +00:00
RegExp(r'@[a-zA-Z0-9]+').hasMatch(ref);
2020-04-29 11:42:01 +00:00
/// Validated a shortcut
bool validateShortcut(String shortcut) =>
RegExp(r'^:[a-zA-Z0-9]+:$').hasMatch(shortcut);