-
Notifications
You must be signed in to change notification settings - Fork 0
/
extensions.dart
39 lines (33 loc) · 978 Bytes
/
extensions.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import 'dart:io';
import 'package:dio/dio.dart';
extension StringExtension on String {
String capitalize() {
var result = this[0].toUpperCase();
for (int i = 1; i < length; i++) {
if (this[i - 1] == " ") {
result = result + this[i].toUpperCase();
} else {
result = result + this[i];
}
}
return result;
}
bool get isValidEmail {
final emailRegExp = RegExp(r"^[a-zA-Z0-9.]+@[a-zA-Z0-9]+\.[a-zA-Z]+");
return emailRegExp.hasMatch(this);
}
bool get isValidPassword {
final passwordRegExp =
RegExp(r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~])');
return passwordRegExp.hasMatch(this);
}
}
extension DioErrorX on DioError {
bool get isNoConnectionError =>
type == DioErrorType.unknown && error is SocketException;
}
extension DateOnlyCompare on DateTime {
bool isSameDate(DateTime other) {
return year == other.year && month == other.month && day == other.day;
}
}