67 lines
1.8 KiB
Dart
67 lines
1.8 KiB
Dart
class Validators {
|
|
static String? validateEmail(String? value) {
|
|
if (value == null || value.isEmpty) {
|
|
return 'Email is required';
|
|
}
|
|
// Regular expression for email validation
|
|
final emailRegex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$');
|
|
if (!emailRegex.hasMatch(value)) {
|
|
return 'Enter a valid email address';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
static String? validatePassword(String? value) {
|
|
if (value == null || value.isEmpty) {
|
|
return 'Password is required';
|
|
}
|
|
if (value.length < 6) {
|
|
return 'Password must be at least 6 characters long';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
static String? validateConfirmPassword(String? value, String password) {
|
|
if (value == null || value.isEmpty) {
|
|
return 'Confirm password is required';
|
|
}
|
|
if (value != password) {
|
|
return 'Passwords do not match';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
static String? validateFullName(String? value) {
|
|
if (value == null || value.isEmpty) {
|
|
return 'Full name is required';
|
|
}
|
|
// Regular expression for full name validation
|
|
final nameRegex = RegExp(r'^[a-zA-Z\s]+$');
|
|
if (!nameRegex.hasMatch(value)) {
|
|
return 'Enter a valid full name';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
static String? validatePhoneNumber(String? value) {
|
|
if (value == null || value.isEmpty) {
|
|
return 'Phone number is required';
|
|
}
|
|
// Regular expression for phone number validation
|
|
final phoneRegex = RegExp(r'^\+?(\d{1,3})?[-. ]?\(?\d{3}\)?[-. ]?\d{3}[-. ]?\d{4}$');
|
|
if (!phoneRegex.hasMatch(value)) {
|
|
return 'Enter a valid phone number';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
static String? validateNotEmpty(String? value, String field) {
|
|
if (value == null || value.isEmpty) {
|
|
return '$field is required';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// Add more validation methods as needed
|
|
}
|