 
             if options.preventInvalidInput == true
               elem.on 'keypress', (e) ->
-                if invalidInput(elem, event, options)
-                  e.preventDefault()
-                  e.stopPropagation()
+                e.preventDefault()
+                e.stopPropagation()
+
+                return if invalidInput(elem, event, options)
+
+                if event.which >= 48 and event.which <= 57 # insert number character
+                  insertCharacter(elem, event)
+
+                # if a key has been pressed and a reformat is required, do it
+                if event.which == 8 # backspace is pressed
+                  if elem.val().length == 4 || elem.val().length == 8 # a new comma is added
+                    newCursorPosition = elem[0].selectionStart - 1
+                  else
+                    newCursorPosition = elem[0].selectionStart
+                else
+                  if elem.val().length == 4 || elem.val().length == 8 # a new comma is added
+                    newCursorPosition = elem[0].selectionStart + 1
+                  else if elem[0].selectionStart < elem.val().length # cursor is adding numbers, but is not at the end of the input field
+                    newCursorPosition = elem[0].selectionStart
+                  else # cursor is adding numbers at the end of the input field
+                    newCursorPosition = elem[0].selectionStart + 1
+
+                elem.val resetCommas(elem.val()) # reformat the number in place
+                elem[0].setSelectionRange(newCursorPosition, newCursorPosition) # set the new cursor position
 
     }
 ]

    moveCursorRight = (elem) ->
      newCursorPos = elem[0].selectionStart + 1
      elem[0].setSelectionRange(newCursorPos, newCursorPos)

    makeIsValid = (options) ->
        validations = []

        link: (scope, elem, attrs, ngModelCtrl) ->
            options = getOptions scope, attrs
            isValid = makeIsValid options
            reformatRequired = false

            ngModelCtrl.$parsers.unshift (viewVal) ->
                noCommasVal = viewVal.replace /,/g, ''
