@@ -168,29 +168,19 @@ public class VNDTextField: UITextField {
168
168
}
169
169
170
170
@objc private func textDidChange( ) {
171
- guard var inputText = self . text else {
172
- return
173
- }
174
-
175
- // remove "đ" from text in textfield
176
- let charecterDeleted = " đ "
177
- inputText. removeAll ( where: { charecterDeleted. contains ( $0) } )
178
-
179
- // remove "." from text in textfield
180
- inputText. removeAll { $0 == " . " }
181
-
182
- // remove space from text in textfield
183
- inputText. removeAll { $0 == " " }
184
-
185
- // format currency text in textfield
186
- if let amountString = Int ( inputText) {
187
- self . text = formatCurrency ( amountString)
171
+ let inputText = getAmount ( )
172
+ if let inputText = Int ( inputText) {
173
+ self . text = formatCurrency ( inputText)
188
174
}
189
175
190
176
if let newPosition = self . position ( from: self . endOfDocument, offset: - 2 ) {
191
177
self . selectedTextRange = self . textRange ( from: newPosition, to: newPosition)
192
178
}
193
179
180
+ guard let inputText = self . text else {
181
+ return
182
+ }
183
+
194
184
if inputText. count > 0 && inputText. count < 4 {
195
185
guard let inputText = Int ( inputText) else {
196
186
return
@@ -241,6 +231,26 @@ public class VNDTextField: UITextField {
241
231
}
242
232
}
243
233
234
+ /// Get text in texfield convert to int
235
+ /// - Returns: interger
236
+ public func getAmount( ) -> String {
237
+ guard var inputText = self . text else {
238
+ return " "
239
+ }
240
+
241
+ // remove symbol from text in textfield
242
+ let charecterDeleted = " đ "
243
+ inputText. removeAll ( where: { charecterDeleted. contains ( $0) } )
244
+
245
+ // remove "." from text in textfield
246
+ inputText. removeAll { $0 == " . " }
247
+
248
+ // remove space from text in textfield
249
+ inputText. removeAll { $0 == " " }
250
+
251
+ return inputText
252
+ }
253
+
244
254
/// Format input number to string
245
255
/// - Parameter inputNumber: ext in textfield as Int
246
256
/// - Parameter symbol: defaufl character = "đ"
0 commit comments