-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidators.dart
More file actions
49 lines (44 loc) · 1.1 KB
/
validators.dart
File metadata and controls
49 lines (44 loc) · 1.1 KB
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
40
41
42
43
44
45
46
47
48
49
// validation logic
class Validators {
Validators._();
static String? nameValidator(String? name) {
if (name!.isNotEmpty) {
if (RegExp(r"^[a-zA-Z ]+$").hasMatch(name)) {
return null;
}
return 'Invalid name';
} else {
return 'Name is required';
}
}
static String? emailValidator(String? email) {
if (email!.isNotEmpty) {
if (RegExp(r"^[a-zA-Z0-9.]+@[a-zA-Z0-9]+\.[a-zA-Z]+").hasMatch(email)) {
return null;
}
} else {
return 'Email is required';
}
return 'Invalid email';
}
static String? passwordValidator(String? password) {
if (password!.isNotEmpty) {
if (password.length < 6) {
return 'Password must be at least 6 characters';
}
return null;
} else {
return 'Password is required';
}
}
static String? phoneNumberValidator(String? phoneNumber) {
if (phoneNumber!.isNotEmpty) {
if (RegExp(r"^[0-9]{11}$").hasMatch(phoneNumber)) {
return null;
}
return 'Invalid phone number';
} else {
return 'Phone number is required';
}
}
}