@@ -61,6 +61,12 @@ final class EditProfileViewModel {
61
61
!description. isEmpty && description. count <= 20
62
62
}
63
63
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
+ }
64
70
var isContactsValid : Bool {
65
71
return contacts. allSatisfy { !$0. value. isEmpty }
66
72
}
@@ -70,10 +76,10 @@ final class EditProfileViewModel {
70
76
isValidBirthDate &&
71
77
!nickname. isEmpty &&
72
78
!description. isEmpty &&
73
- !birthDate . isEmpty &&
79
+ isValidBirthDate &&
74
80
!location. isEmpty &&
75
- !height . isEmpty &&
76
- !weight . isEmpty &&
81
+ isValidHeight &&
82
+ isVaildWeight &&
77
83
!job. isEmpty &&
78
84
isContactsValid
79
85
}
@@ -138,13 +144,17 @@ final class EditProfileViewModel {
138
144
var heightInfoText : String {
139
145
if height. isEmpty && didTapnextButton {
140
146
return " 필수 항목을 입력해 주세요. "
147
+ } else if !height. isEmpty && !( ( 2 ... 3 ) . contains ( height. count) && height. allSatisfy ( \. isNumber) ) {
148
+ return " 숫자가 정확한 지 확인해 주세요. "
141
149
} else {
142
150
return " "
143
151
}
144
152
}
145
153
var weightInfoText : String {
146
154
if weight. isEmpty && didTapnextButton {
147
155
return " 필수 항목을 입력해 주세요. "
156
+ } else if !weight. isEmpty && !( ( 2 ... 3 ) . contains ( weight. count) && weight. allSatisfy ( \. isNumber) ) {
157
+ return " 숫자가 정확한 지 확인해 주세요. "
148
158
} else {
149
159
return " "
150
160
}
@@ -299,11 +309,18 @@ final class EditProfileViewModel {
299
309
}
300
310
301
311
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
303
313
let dateTest = NSPredicate ( format: " SELF MATCHES %@ " , dateRegex)
304
314
return dateTest. evaluate ( with: date) && date. count == 8
305
315
}
306
316
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
+
307
324
func saveSelectedJob( ) {
308
325
if isCustomJobSelected {
309
326
self . job = customJobText. isEmpty ? " " : customJobText
@@ -392,7 +409,7 @@ final class EditProfileViewModel {
392
409
393
410
nickname = profile. nickname
394
411
description = profile. description
395
- birthDate = profile. birthdate
412
+ birthDate = profile. birthdate. toCompactDateString
396
413
location = profile. location
397
414
height = String ( profile. height)
398
415
weight = String ( profile. weight)
0 commit comments