Files
lunchpick/lib/core/utils/validators.dart
2025-11-19 16:36:39 +09:00

93 lines
2.3 KiB
Dart

class Validators {
static String? validateRestaurantName(String? value) {
if (value == null || value.trim().isEmpty) {
return '맛집 이름을 입력해주세요';
}
if (value.trim().length < 2) {
return '맛집 이름은 2자 이상이어야 합니다';
}
if (value.trim().length > 50) {
return '맛집 이름은 50자 이하여야 합니다';
}
return null;
}
static String? validateMemo(String? value) {
if (value != null && value.length > 200) {
return '메모는 200자 이하여야 합니다';
}
return null;
}
static String? validateLatitude(String? value) {
if (value == null || value.isEmpty) {
return null;
}
final lat = double.tryParse(value);
if (lat == null) {
return '올바른 위도 값을 입력해주세요';
}
if (lat < -90 || lat > 90) {
return '위도는 -90도에서 90도 사이여야 합니다';
}
return null;
}
static String? validateLongitude(String? value) {
if (value == null || value.isEmpty) {
return null;
}
final lng = double.tryParse(value);
if (lng == null) {
return '올바른 경도 값을 입력해주세요';
}
if (lng < -180 || lng > 180) {
return '경도는 -180도에서 180도 사이여야 합니다';
}
return null;
}
static String? validateAddress(String? value) {
if (value != null && value.length > 100) {
return '주소는 100자 이하여야 합니다';
}
return null;
}
static String? validateCategory(String? value) {
if (value == null || value.isEmpty) {
return '카테고리를 선택해주세요';
}
return null;
}
static String? validateRating(double? value) {
if (value != null && (value < 0 || value > 5)) {
return '평점은 0에서 5 사이여야 합니다';
}
return null;
}
static bool isValidEmail(String? email) {
if (email == null || email.isEmpty) return false;
final emailRegex = RegExp(
r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$',
);
return emailRegex.hasMatch(email);
}
static bool isValidPhoneNumber(String? phone) {
if (phone == null || phone.isEmpty) return false;
final phoneRegex = RegExp(r'^[0-9-+() ]+$');
return phoneRegex.hasMatch(phone) && phone.length >= 10;
}
}