             guard let text = text else {
                 return nil
             }
-            var cursorPosition = 0
-            let unformattedText = self.unformatterText(fromText: text, textMask: textMask, cursorPosition: &cursorPosition)
+            guard let formatter = textFormatter else {
+                return text
+            }
+            let unformattedText = formatter.unformattedText(from: text)
 
             return unformattedText
         }
         set(value) {
-            var cursorPosition = 0
-            let unformattedText = value ?? ""
-            let formattedText = self.formattedText(fromText: unformattedText, textMask: textMask, cursorPosition: &cursorPosition)
+            var formattedText = (value ?? "")
+            if let formatter = textFormatter {
+                formattedText = formatter.formattedText(from: formattedText)
+            }
+
             if formattedText.characters.count > 0 || value != nil {
                 text = formattedText
             } else {
                 text = nil
             }
-            placeholderLabel.isHidden = (unformattedText.characters.count > 0)
+            placeholderLabel.isHidden = (formattedText.characters.count > 0)
         }
     }
 

        super.delegate = delegateProxy

        if let unformattedText = unformattedText {
            var cursorPosition = 0
            text = formattedText(fromText: unformattedText, textMask: text, cursorPosition: &cursorPosition)
        }

        placeholderLabel.font = font

        addSubview(placeholderLabel)
    }

    @IBInspectable open var textFormatter: TextFromatter? {
        didSet(oldFormatter) {
            let text = (self.text ?? "")
            let selectedRange = selectedCharactersRange ?? text.startIndex..<text.startIndex

            var unformattedText = text
            var unformattedRange = selectedRange
            if let oldFormatter = oldFormatter {
                (unformattedText, unformattedRange) = oldFormatter.unformattedText(from: text, range: selectedRange)
            }

            var formattedText = unformattedText
            var formattedRange = unformattedRange
            if let formatter = textFormatter {
                (formattedText, formattedRange) = formatter.formattedText(from: unformattedText, range: unformattedRange)
            }

            self.text = formattedText
            if selectedTextRange != nil {
                selectedCharactersRange = formattedRange.upperBound..<formattedRange.upperBound
            }
        }
    }
