Skip to content

Commit

Permalink
Merge pull request #1 from ios-lib/develop
Browse files Browse the repository at this point in the history
get amount string
  • Loading branch information
lexuanquynh committed Jun 28, 2021
2 parents 83f371a + 1a200e6 commit 4728784
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions Sources/VNDTextField/VNDTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,29 +168,19 @@ public class VNDTextField: UITextField {
}

@objc private func textDidChange() {
guard var inputText = self.text else {
return
}

// remove "đ" from text in textfield
let charecterDeleted = "đ"
inputText.removeAll(where: { charecterDeleted.contains($0) })

// remove "." from text in textfield
inputText.removeAll { $0 == "." }

// remove space from text in textfield
inputText.removeAll { $0 == " " }

// format currency text in textfield
if let amountString = Int(inputText) {
self.text = formatCurrency(amountString)
let inputText = getAmount()
if let inputText = Int(inputText) {
self.text = formatCurrency(inputText)
}

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

guard let inputText = self.text else {
return
}

if inputText.count > 0 && inputText.count < 4 {
guard let inputText = Int(inputText) else {
return
Expand Down Expand Up @@ -241,6 +231,26 @@ public class VNDTextField: UITextField {
}
}

/// Get text in texfield convert to int
/// - Returns: interger
public func getAmount() -> String {
guard var inputText = self.text else {
return ""
}

// remove symbol from text in textfield
let charecterDeleted = "đ"
inputText.removeAll(where: { charecterDeleted.contains($0) })

// remove "." from text in textfield
inputText.removeAll { $0 == "." }

// remove space from text in textfield
inputText.removeAll { $0 == " " }

return inputText
}

/// Format input number to string
/// - Parameter inputNumber: ext in textfield as Int
/// - Parameter symbol: defaufl character = "đ"
Expand Down

0 comments on commit 4728784

Please sign in to comment.