Skip to content

Commit 4728784

Browse files
authored
Merge pull request #1 from ios-lib/develop
get amount string
2 parents 83f371a + 1a200e6 commit 4728784

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

Sources/VNDTextField/VNDTextField.swift

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -168,29 +168,19 @@ public class VNDTextField: UITextField {
168168
}
169169

170170
@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)
188174
}
189175

190176
if let newPosition = self.position(from: self.endOfDocument, offset: -2) {
191177
self.selectedTextRange = self.textRange(from: newPosition, to: newPosition)
192178
}
193179

180+
guard let inputText = self.text else {
181+
return
182+
}
183+
194184
if inputText.count > 0 && inputText.count < 4 {
195185
guard let inputText = Int(inputText) else {
196186
return
@@ -241,6 +231,26 @@ public class VNDTextField: UITextField {
241231
}
242232
}
243233

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+
244254
/// Format input number to string
245255
/// - Parameter inputNumber: ext in textfield as Int
246256
/// - Parameter symbol: defaufl character = "đ"

0 commit comments

Comments
 (0)