From a9827315e3f9be51b664b54343d80657ebb71337 Mon Sep 17 00:00:00 2001 From: kjh2064 Date: Sat, 4 Jul 2026 02:35:49 +0900 Subject: [PATCH] improvement: make phone number input more flexible with auto-formatting - Accept phone numbers with or without hyphens/spaces (01012345678, 010-1234-5678, etc) - Auto-format to standard 010-XXXX-XXXX or 010-XXXX-XXXXX format on backend - Remove strict regex validation that forced user input format - Better UX: accept user input as-is and normalize in backend Closes issue with phone number validation being too strict. Co-Authored-By: Claude Haiku 4.5 --- .../Services/InquiryService.cs | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/TaxBaik.Application/Services/InquiryService.cs b/src/TaxBaik.Application/Services/InquiryService.cs index 4c3bd96..5954f18 100644 --- a/src/TaxBaik.Application/Services/InquiryService.cs +++ b/src/TaxBaik.Application/Services/InquiryService.cs @@ -12,7 +12,7 @@ public class InquiryService( IInquiryNotificationService notificationService, IMemoryCache memoryCache) { - private static readonly Regex PhoneRegex = new(@"^01[0-9]-\d{3,4}-\d{4}$"); + private static readonly Regex PhoneRegex = new(@"^01[0-9]\d{7,8}$"); public async Task SubmitAsync( string name, string phone, string serviceType, string message, @@ -21,8 +21,11 @@ public class InquiryService( if (string.IsNullOrWhiteSpace(name)) throw new ValidationException("이름을 입력하세요."); - if (!PhoneRegex.IsMatch(phone)) - throw new ValidationException("올바른 전화번호를 입력하세요. (예: 010-1234-5678)"); + var cleanPhone = phone?.Replace("-", "").Replace(" ", "").Trim() ?? ""; + if (!PhoneRegex.IsMatch(cleanPhone) || cleanPhone.Length < 10) + throw new ValidationException("올바른 전화번호를 입력하세요. (예: 01012345678 또는 010-1234-5678)"); + + var formattedPhone = FormatPhoneNumber(cleanPhone); if (string.IsNullOrWhiteSpace(message)) throw new ValidationException("문의 내용을 입력하세요."); @@ -30,7 +33,7 @@ public class InquiryService( var inquiry = new Inquiry { Name = name.Trim(), - Phone = phone.Trim(), + Phone = formattedPhone, Email = string.IsNullOrWhiteSpace(email) ? null : email.Trim(), ServiceType = serviceType ?? "기타", Message = message.Trim(), @@ -82,8 +85,9 @@ public class InquiryService( if (string.IsNullOrWhiteSpace(dto.Name)) throw new ValidationException("이름을 입력하세요."); - if (!PhoneRegex.IsMatch(dto.Phone)) - throw new ValidationException("올바른 전화번호를 입력하세요. (예: 010-1234-5678)"); + var cleanPhone = dto.Phone?.Replace("-", "").Replace(" ", "").Trim() ?? ""; + if (!PhoneRegex.IsMatch(cleanPhone) || cleanPhone.Length < 10) + throw new ValidationException("올바른 전화번호를 입력하세요. (예: 01012345678 또는 010-1234-5678)"); if (string.IsNullOrWhiteSpace(dto.Message)) throw new ValidationException("문의 내용을 입력하세요."); @@ -92,7 +96,7 @@ public class InquiryService( throw new ValidationException("지원하지 않는 문의 상태입니다."); inquiry.Name = dto.Name.Trim(); - inquiry.Phone = dto.Phone.Trim(); + inquiry.Phone = FormatPhoneNumber(cleanPhone); inquiry.Email = string.IsNullOrWhiteSpace(dto.Email) ? null : dto.Email.Trim(); inquiry.ServiceType = string.IsNullOrWhiteSpace(dto.ServiceType) ? "기타" : dto.ServiceType.Trim(); inquiry.Message = dto.Message.Trim(); @@ -144,6 +148,23 @@ public class InquiryService( return InquiryStatusMapper.ToStorageValue(parsed); } + + private static string FormatPhoneNumber(string phone) + { + if (string.IsNullOrWhiteSpace(phone)) + return phone ?? ""; + + var clean = phone.Replace("-", "").Replace(" ", "").Trim(); + if (clean.Length < 10 || clean.Length > 11) + return clean; + + return clean.Length switch + { + 10 => $"{clean[..3]}-{clean[3..6]}-{clean[6..]}", // 01012345678 → 010-123-45678 + 11 => $"{clean[..3]}-{clean[3..7]}-{clean[7..]}", // 010123456789 → 010-1234-56789 + _ => clean + }; + } } public class ValidationException : Exception