         let cursorOffset = getOriginalCursorPosition();
         
         let cleanNumericString : String = getCleanNumberString()
+        let textFieldLength = self.text?.characters.count
        
         if cleanNumericString.characters.count > maxDigits{
             self.text = previousValue

        return cursorOffset
    }
    
    private func setCursorOriginalPosition(cursorOffset: Int){
        
        let textFieldLength = self.text?.characters.count
        let newLength = self.text?.characters.count
        let startPosition : UITextPosition = self.beginningOfDocument
        if let textFieldLength = textFieldLength, newLength = newLength where textFieldLength > cursorOffset{
            let newOffset = newLength - textFieldLength - cursorOffset
            let newCursorPosition = self.positionFromPosition(startPosition, offset: newOffset)
            if let newCursorPosition = newCursorPosition{
                let newSelectedRange = self.textRangeFromPosition(newCursorPosition, toPosition: newCursorPosition)

            }
        }
        //Set the cursor back to its original poistion
        setCursorOriginalPosition(cursorOffset, oldTextFieldLength: textFieldLength)
    }
    
    //MARK: - Custom text field functions
