Skip to content

Commit f2507bd

Browse files
authored
Merge pull request #124 from YAPP-Github/fix/PC-745-textfield-regex
[PC-745] Fix: 프로필 생성, 수정 화면 텍스트필드 정규식 적용
2 parents ab2a66c + cdaeec8 commit f2507bd

File tree

7 files changed

+64
-18
lines changed

7 files changed

+64
-18
lines changed

Data/DTO/Sources/Profile/ProfileBasicResponseDTO.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public extension ProfileBasicResponseDTO {
3030
nickname: nickname,
3131
description: description,
3232
age: age,
33-
birthdate: birthdate.extractYear(),
33+
birthdate: birthdate,
3434
height: height,
3535
weight: weight,
3636
job: job,

Presentation/Feature/EditProfile/Sources/EditProfileView.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ struct EditProfileView: View {
413413
text: Binding(
414414
get: { contact.value },
415415
set: { newValue in
416-
if let index = viewModel.contacts.firstIndex(where: { $0.id == contact.id }) {
416+
if viewModel.isAllowedInput(newValue),
417+
let index = viewModel.contacts.firstIndex(where: { $0.id == contact.id }) {
417418
viewModel.contacts[index].value = newValue
418419
}
419420
}
@@ -433,6 +434,8 @@ struct EditProfileView: View {
433434
viewModel.isContactTypeChangeSheetPresented = true
434435
}
435436
)
437+
.textInputAutocapitalization(.never)
438+
.autocorrectionDisabled(true)
436439
.frame(minHeight: 72)
437440
.id("contact_\(contact.id)_scroll")
438441
}

Presentation/Feature/EditProfile/Sources/EditProfileViewModel.swift

+22-5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ final class EditProfileViewModel {
6161
!description.isEmpty && description.count <= 20
6262
}
6363
var isValidBirthDate: Bool { isValidBirthDateFormat(birthDate) }
64+
var isValidHeight: Bool {
65+
(2...3).contains(height.count) && height.allSatisfy(\.isNumber)
66+
}
67+
var isVaildWeight: Bool {
68+
(2...3).contains(weight.count) && weight.allSatisfy(\.isNumber)
69+
}
6470
var isContactsValid: Bool {
6571
return contacts.allSatisfy { !$0.value.isEmpty }
6672
}
@@ -70,10 +76,10 @@ final class EditProfileViewModel {
7076
isValidBirthDate &&
7177
!nickname.isEmpty &&
7278
!description.isEmpty &&
73-
!birthDate.isEmpty &&
79+
isValidBirthDate &&
7480
!location.isEmpty &&
75-
!height.isEmpty &&
76-
!weight.isEmpty &&
81+
isValidHeight &&
82+
isVaildWeight &&
7783
!job.isEmpty &&
7884
isContactsValid
7985
}
@@ -138,13 +144,17 @@ final class EditProfileViewModel {
138144
var heightInfoText: String {
139145
if height.isEmpty && didTapnextButton {
140146
return "필수 항목을 입력해 주세요."
147+
} else if !height.isEmpty && !((2...3).contains(height.count) && height.allSatisfy(\.isNumber)) {
148+
return "숫자가 정확한 지 확인해 주세요."
141149
} else {
142150
return ""
143151
}
144152
}
145153
var weightInfoText: String {
146154
if weight.isEmpty && didTapnextButton {
147155
return "필수 항목을 입력해 주세요."
156+
} else if !weight.isEmpty && !((2...3).contains(weight.count) && weight.allSatisfy(\.isNumber)) {
157+
return "숫자가 정확한 지 확인해 주세요."
148158
} else {
149159
return ""
150160
}
@@ -299,11 +309,18 @@ final class EditProfileViewModel {
299309
}
300310

301311
private func isValidBirthDateFormat(_ date: String) -> Bool {
302-
let dateRegex = "^[0-9]{8}$" // YYYYMMDD
312+
let dateRegex = #"^(19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])$"# // YYYYMMDD
303313
let dateTest = NSPredicate(format: "SELF MATCHES %@", dateRegex)
304314
return dateTest.evaluate(with: date) && date.count == 8
305315
}
306316

317+
func isAllowedInput(_ input: String) -> Bool {
318+
let pattern = #"^[A-Za-z0-9\s[:punct:][:symbol:]]*$"#
319+
guard let regex = try? NSRegularExpression(pattern: pattern) else { return false }
320+
let range = NSRange(location: 0, length: input.utf16.count)
321+
return regex.firstMatch(in: input, options: [], range: range) != nil
322+
}
323+
307324
func saveSelectedJob() {
308325
if isCustomJobSelected {
309326
self.job = customJobText.isEmpty ? "" : customJobText
@@ -392,7 +409,7 @@ final class EditProfileViewModel {
392409

393410
nickname = profile.nickname
394411
description = profile.description
395-
birthDate = profile.birthdate
412+
birthDate = profile.birthdate.toCompactDateString
396413
location = profile.location
397414
height = String(profile.height)
398415
weight = String(profile.weight)

Presentation/Feature/MatchingMain/Sources/MatchingMainView.swift

+8-6
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,19 @@ struct MatchingMainView: View {
142142

143143
VStack {
144144
VStack(alignment: .center, spacing: 8) {
145-
Text("진중한 만남")
146-
.foregroundStyle(Color.primary) +
147-
Text("을 이어가기 위해\n프로필을 살펴보고 있어요")
148-
.foregroundStyle(Color.grayscaleBlack)
145+
Group {
146+
Text("진중한 만남")
147+
.foregroundStyle(Color.primaryDefault) +
148+
Text("을 이어가기 위해\n프로필을 살펴보고 있어요")
149+
.foregroundStyle(Color.grayscaleBlack)
150+
}
151+
.pretendard(.heading_M_SB)
149152
Text("작성 후 24시간 이내에 심사가 진행됩니다.\n생성한 프로필을 검토하며 기다려 주세요.")
150-
.pretendard(.heading_S_M)
153+
.pretendard(.body_S_M)
151154
.foregroundStyle(Color.grayscaleDark3)
152155
}
153156
.padding(.top, 40)
154157
.padding(.bottom, 20)
155-
.pretendard(.heading_M_SB)
156158
.multilineTextAlignment(.center)
157159

158160
DesignSystemAsset.Images.imgScreening.swiftUIImage

Presentation/Feature/SignUp/Sources/CreateProfile/BasicInfo/CreateBasicInfoView.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ struct CreateBasicInfoView: View {
398398
text: Binding(
399399
get: { contact.value },
400400
set: { newValue in
401-
if let index = viewModel.contacts.firstIndex(where: { $0.id == contact.id }) {
401+
if viewModel.isAllowedInput(newValue),
402+
let index = viewModel.contacts.firstIndex(where: { $0.id == contact.id }) {
402403
viewModel.contacts[index].value = newValue
403404
}
404405
}
@@ -418,6 +419,8 @@ struct CreateBasicInfoView: View {
418419
viewModel.isContactTypeChangeSheetPresented = true
419420
}
420421
)
422+
.textInputAutocapitalization(.never)
423+
.autocorrectionDisabled(true)
421424
.frame(minHeight: 72)
422425
.id("contact_\(contact.id)_scroll")
423426
}

Presentation/Feature/SignUp/Sources/CreateProfile/BasicInfo/CreateBasicInfoViewModel.swift

+21-4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ final class CreateBasicInfoViewModel {
5454
!description.isEmpty && description.count <= 20
5555
}
5656
var isValidBirthDate: Bool { isValidBirthDateFormat(birthDate) }
57+
var isValidHeight: Bool {
58+
(2...3).contains(height.count) && height.allSatisfy(\.isNumber)
59+
}
60+
var isVaildWeight: Bool {
61+
(2...3).contains(weight.count) && weight.allSatisfy(\.isNumber)
62+
}
5763
var isContactsValid: Bool {
5864
return contacts.allSatisfy { !$0.value.isEmpty }
5965
}
@@ -63,10 +69,10 @@ final class CreateBasicInfoViewModel {
6369
isValidBirthDate &&
6470
!nickname.isEmpty &&
6571
!description.isEmpty &&
66-
!birthDate.isEmpty &&
72+
isValidBirthDate &&
6773
!location.isEmpty &&
68-
!height.isEmpty &&
69-
!weight.isEmpty &&
74+
isValidHeight &&
75+
isVaildWeight &&
7076
!job.isEmpty &&
7177
isContactsValid
7278
}
@@ -120,13 +126,17 @@ final class CreateBasicInfoViewModel {
120126
var heightInfoText: String {
121127
if height.isEmpty && didTapnextButton {
122128
return "필수 항목을 입력해 주세요."
129+
} else if !height.isEmpty && !((2...3).contains(height.count) && height.allSatisfy(\.isNumber)) {
130+
return "숫자가 정확한 지 확인해 주세요."
123131
} else {
124132
return ""
125133
}
126134
}
127135
var weightInfoText: String {
128136
if weight.isEmpty && didTapnextButton {
129137
return "필수 항목을 입력해 주세요."
138+
} else if !weight.isEmpty && !((2...3).contains(weight.count) && weight.allSatisfy(\.isNumber)) {
139+
return "숫자가 정확한 지 확인해 주세요."
130140
} else {
131141
return ""
132142
}
@@ -284,11 +294,18 @@ final class CreateBasicInfoViewModel {
284294
}
285295

286296
private func isValidBirthDateFormat(_ date: String) -> Bool {
287-
let dateRegex = "^[0-9]{8}$" // YYYYMMDD
297+
let dateRegex = #"^(19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])$"# // YYYYMMDD
288298
let dateTest = NSPredicate(format: "SELF MATCHES %@", dateRegex)
289299
return dateTest.evaluate(with: date) && date.count == 8
290300
}
291301

302+
func isAllowedInput(_ input: String) -> Bool {
303+
let pattern = #"^[A-Za-z0-9\s[:punct:][:symbol:]]*$"#
304+
guard let regex = try? NSRegularExpression(pattern: pattern) else { return false }
305+
let range = NSRange(location: 0, length: input.utf16.count)
306+
return regex.firstMatch(in: input, options: [], range: range) != nil
307+
}
308+
292309
func saveSelectedJob() {
293310
if isCustomJobSelected {
294311
self.job = customJobText.isEmpty ? "" : customJobText

Utility/PCFoundationExtension/Sources/String+Extension.swift

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public extension String {
1717

1818
return lastTwoDigits
1919
}
20+
21+
var toCompactDateString: String {
22+
return self.replacingOccurrences(of: "-", with: "")
23+
}
2024
}
2125

2226
// MARK: - decodeJWT

0 commit comments

Comments
 (0)