feat: implement proper Korean phone number validation and formatting
TaxBaik CI/CD / build-and-deploy (push) Successful in 3m23s

- Add comprehensive Korean phone number regex validation
- Support all area codes: 02, 031-064, 070, 0505-0509
- Support all mobile carriers: 010-019
- Intelligent formatting based on area code (2-3 digits)
- Client-side JavaScript: real-time formatting + validation
- Backend C#: robust validation + formatting for storage

Handles all Korean phone number formats:
- Landline: 02-123-4567, 031-1234-5678
- Mobile: 010-1234-5678
- VoIP: 070-1234-5678, 0505-1234-5678

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-07-04 02:43:37 +09:00
parent caf7e5cf9f
commit 66d6ae88f1
2 changed files with 88 additions and 20 deletions
+33 -13
View File
@@ -90,6 +90,9 @@
const phoneError = document.getElementById('phoneError');
const contactForm = document.getElementById('contactForm');
// 한국 전화번호 정규식
const koreanPhoneRegex = /^(0(2|3[1-3]|4[1-4]|5[1-5]|6[1-4]|70|50[5-9]|[7-9](?:\d{1,2})?)\d{7,8}|0\d{9,10})$/;
// 실시간 전화번호 마스킹
phoneInput.addEventListener('input', (e) => {
let value = e.target.value.replace(/\D/g, ''); // 숫자만 추출
@@ -99,26 +102,43 @@
}
// 포맷팅
if (value.length >= 10) {
if (value.length === 10) {
// 10자리: XXXX-XXX-XXXX
value = `${value.substring(0, 4)}-${value.substring(4, 7)}-${value.substring(7)}`;
} else if (value.length === 11) {
// 11자리: XXX-XXXX-XXXX
value = `${value.substring(0, 3)}-${value.substring(3, 7)}-${value.substring(7)}`;
}
} else if (value.length > 3) {
value = `${value.substring(0, 3)}-${value.substring(3)}`;
}
value = formatKoreanPhoneNumber(value);
e.target.value = value;
validatePhone();
});
// 한국 전화번호 포맷팅
function formatKoreanPhoneNumber(value) {
if (!value.startsWith('0')) return value;
let areaCode = '';
if (value.startsWith('02')) {
areaCode = '02';
} else if ((value.startsWith('070') ||
(value.startsWith('050') && value.length > 2 && value[3] >= '5' && value[3] <= '9')) ||
(value.length >= 3 && /^0[3-6]\d/.test(value))) {
areaCode = value.substring(0, 3);
} else if (value.length >= 3 && value.startsWith('01')) {
areaCode = value.substring(0, 3);
}
if (!areaCode) return value;
const restPart = value.substring(areaCode.length);
if (restPart.length === 7) {
return `${areaCode}-${restPart.substring(0, 3)}-${restPart.substring(3)}`;
} else if (restPart.length === 8) {
return `${areaCode}-${restPart.substring(0, 4)}-${restPart.substring(4)}`;
} else if (restPart.length > 0 && restPart.length < 7) {
return `${areaCode}-${restPart}`;
}
return value;
}
// 전화번호 검증
function validatePhone() {
const value = phoneInput.value.replace(/\D/g, '');
const isValid = value.length >= 10 && value.length <= 11;
const isValid = koreanPhoneRegex.test(value);
if (!isValid && phoneInput.value.length > 0) {
phoneError.style.display = 'block';