diff --git a/_layouts/master.html b/_layouts/master.html
index ec4b91b..e62086f 100644
--- a/_layouts/master.html
+++ b/_layouts/master.html
@@ -40,7 +40,7 @@
     </div>
     <script src="http://code.jquery.com/jquery-1.10.1.js"></script>
     <script src="javascripts/scale.fix.js"></script>
-    <script src="javascripts/formatter.min.js"></script>
+    <script src="javascripts/formatter.js"></script>
     {% raw %}
     <script>
       // $('#phone-input').formatter({
diff --git a/javascripts/formatter.js b/javascripts/formatter.js
index 551d30d..f5255db 100644
--- a/javascripts/formatter.js
+++ b/javascripts/formatter.js
@@ -1,5 +1,5 @@
 /*!
- * v0.0.9
+ * v0.1.3
  * Copyright (c) 2014 First Opinion
  * formatter.js is open sourced under the MIT license.
  *
@@ -114,7 +114,7 @@ var utils = function () {
     // Define module
     var utils = {};
     // Useragent info for keycode handling
-    var uAgent = typeof navigator !== 'undefined' ? navigator.userAgent : null, iPhone = /iphone/i.test(uAgent);
+    var uAgent = typeof navigator !== 'undefined' ? navigator.userAgent : null;
     //
     // Shallow copy properties from n objects to destObj
     //
@@ -172,28 +172,110 @@ var utils = function () {
       }
     };
     //
-    // Returns true/false if k is a del key
+    // Loop over object and checking for matching properties
     //
-    utils.isDelKey = function (k) {
-      return k === 8 || k === 46 || iPhone && k === 127;
+    utils.getMatchingKey = function (which, keyCode, keys) {
+      // Loop over and return if matched.
+      for (var k in keys) {
+        var key = keys[k];
+        if (which === key.which && keyCode === key.keyCode) {
+          return k;
+        }
+      }
     };
     //
-    // Returns true/false if k is an arrow key
+    // Returns true/false if k is a del keyDown
     //
-    utils.isSpecialKey = function (k) {
-      var codes = {
-          '9': 'tab',
-          '13': 'enter',
-          '35': 'end',
-          '36': 'home',
-          '37': 'leftarrow',
-          '38': 'uparrow',
-          '39': 'rightarrow',
-          '40': 'downarrow',
-          '116': 'F5'
+    utils.isDelKeyDown = function (which, keyCode) {
+      var keys = {
+          'backspace': {
+            'which': 8,
+            'keyCode': 8
+          },
+          'delete': {
+            'which': 46,
+            'keyCode': 46
+          }
         };
-      // If del or special key
-      return codes[k];
+      return utils.getMatchingKey(which, keyCode, keys);
+    };
+    //
+    // Returns true/false if k is a del keyPress
+    //
+    utils.isDelKeyPress = function (which, keyCode) {
+      var keys = {
+          'backspace': {
+            'which': 8,
+            'keyCode': 8,
+            'shiftKey': false
+          },
+          'delete': {
+            'which': 0,
+            'keyCode': 46
+          }
+        };
+      return utils.getMatchingKey(which, keyCode, keys);
+    };
+    // //
+    // // Determine if keydown relates to specialKey
+    // //
+    // utils.isSpecialKeyDown = function (which, keyCode) {
+    //   var keys = {
+    //     'tab': { 'which': 9, 'keyCode': 9 },
+    //     'enter': { 'which': 13, 'keyCode': 13 },
+    //     'end': { 'which': 35, 'keyCode': 35 },
+    //     'home': { 'which': 36, 'keyCode': 36 },
+    //     'leftarrow': { 'which': 37, 'keyCode': 37 },
+    //     'uparrow': { 'which': 38, 'keyCode': 38 },
+    //     'rightarrow': { 'which': 39, 'keyCode': 39 },
+    //     'downarrow': { 'which': 40, 'keyCode': 40 },
+    //     'F5': { 'which': 116, 'keyCode': 116 }
+    //   };
+    //   return utils.getMatchingKey(which, keyCode, keys);
+    // };
+    //
+    // Determine if keypress relates to specialKey
+    //
+    utils.isSpecialKeyPress = function (which, keyCode) {
+      var keys = {
+          'tab': {
+            'which': 0,
+            'keyCode': 9
+          },
+          'enter': {
+            'which': 13,
+            'keyCode': 13
+          },
+          'end': {
+            'which': 0,
+            'keyCode': 35
+          },
+          'home': {
+            'which': 0,
+            'keyCode': 36
+          },
+          'leftarrow': {
+            'which': 0,
+            'keyCode': 37
+          },
+          'uparrow': {
+            'which': 0,
+            'keyCode': 38
+          },
+          'rightarrow': {
+            'which': 0,
+            'keyCode': 39
+          },
+          'downarrow': {
+            'which': 0,
+            'keyCode': 40
+          },
+          'F5': {
+            'which': 116,
+            'keyCode': 116
+          }
+        };
+      return utils.getMatchingKey(which, keyCode, keys);
     };
     //
     // Returns true/false if modifier key is held down
@@ -493,7 +575,7 @@ var formatter = function (patternMatcher, inptSel, utils) {
       // The first thing we need is the character code
       var k = evt.which || evt.keyCode;
       // If delete key
-      if (k && utils.isDelKey(k)) {
+      if (k && utils.isDelKeyDown(evt.which, evt.keyCode)) {
         // Process the keyCode and prevent default
         this._processKey(null, k);
         return utils.preventDefault(evt);
@@ -509,14 +591,10 @@ var formatter = function (patternMatcher, inptSel, utils) {
       var k, isSpecial;
       // Mozilla will trigger on special keys and assign the the value 0
       // We want to use that 0 rather than the keyCode it assigns.
-      if (evt.which) {
-        k = evt.which;
-      } else {
-        k = evt.keyCode;
-        isSpecial = utils.isSpecialKey(k);
-      }
+      k = evt.which || evt.keyCode;
+      isSpecial = utils.isSpecialKeyPress(evt.which, evt.keyCode);
       // Process the keyCode and prevent default
-      if (!utils.isDelKey(k) && !isSpecial && !utils.isModifier(evt)) {
+      if (!utils.isDelKeyPress(evt.which, evt.keyCode) && !isSpecial && !utils.isModifier(evt)) {
         this._processKey(String.fromCharCode(k), false);
         return utils.preventDefault(evt);
       }
@@ -552,7 +630,7 @@ var formatter = function (patternMatcher, inptSel, utils) {
     // @private
     // Using the provided key information, alter el value.
     //
-    Formatter.prototype._processKey = function (chars, delKey, ingoreCaret) {
+    Formatter.prototype._processKey = function (chars, delKey, ignoreCaret) {
       // Get current state
       this.sel = inptSel.get(this.el);
       this.val = this.el.value;
@@ -566,13 +644,8 @@ var formatter = function (patternMatcher, inptSel, utils) {
         this._delete();
       } else if (delKey && this.sel.begin - 1 >= 0) {
         // Always have a delta of at least -1 for the character being deleted.
+        this.val = utils.removeChars(this.val, this.sel.end - 1, this.sel.end);
         this.delta -= 1;
-        // Count number of additional format chars to be deleted. (A group of multiple format chars should be deleted like one value char.)
-        while (this.chars[this.focus - 1]) {
-          this.delta--;
-          this.focus--;
-        }
-        this.val = utils.removeChars(this.val, this.sel.end + this.delta, this.sel.end);
       } else if (delKey) {
         return true;
       }
@@ -583,7 +656,7 @@ var formatter = function (patternMatcher, inptSel, utils) {
         this.delta += chars.length;
       }
       // Format el.value (also handles updating caret position)
-      this._formatValue(ingoreCaret);
+      this._formatValue(ignoreCaret);
     };
     //
     // @private
@@ -704,10 +777,11 @@ var formatter = function (patternMatcher, inptSel, utils) {
           this.focus++;
         }
       } else {
-        // Avoid caching val.length and this.focus, as they may change in _addChar.
+        // Avoid caching val.length, as they may change in _addChar.
         for (var j = 0; j <= this.val.length; j++) {
-          // When moving backwards, i.e. delting characters, don't add format characters past focus point.
-          if (this.delta <= 0 && j === this.focus && this.chars[j] === undefined || this.focus === 0) {
+          // When moving backwards there are some race conditions where we
+          // dont want to add the character
+          if (this.delta <= 0 && j === this.focus) {
             return true;
           }
           // Place character in current position of the formatted string.
diff --git a/javascripts/formatter.min.js b/javascripts/formatter.min.js
index d64eb54..1b78053 100644
--- a/javascripts/formatter.min.js
+++ b/javascripts/formatter.min.js
@@ -1 +1 @@
-!function(a,b){"function"==typeof define&&define.amd?define([],function(){return a.returnExportsGlobal=b()}):"object"==typeof exports?module.exports=b():a.Formatter=b()}(this,function(){var a=function(){var a={},b=4,c=new RegExp("{{([^}]+)}}","g"),d=function(a){for(var b,d=[];b=c.exec(a);)d.push(b);return d};return a.parse=function(a){var c={inpts:{},chars:{}},e=d(a),f=a.length,g=0,h=0,i=0,j=function(a){for(var d=a.length,e=0;d>e;e++)c.inpts[h]=a.charAt(e),h++;g++,i+=a.length+b-1};for(i;f>i;i++)g<e.length&&i===e[g].index?j(e[g][1]):c.chars[i-g*b]=a.charAt(i);return c.mLength=i-g*b,c},a}(),b=function(){var a={},b="undefined"!=typeof navigator?navigator.userAgent:null,c=/iphone/i.test(b);return a.extend=function(a){for(var b=1;b<arguments.length;b++)for(var c in arguments[b])a[c]=arguments[b][c];return a},a.addChars=function(a,b,c){return a.substr(0,c)+b+a.substr(c,a.length)},a.removeChars=function(a,b,c){return a.substr(0,b)+a.substr(c,a.length)},a.isBetween=function(a,b){return b.sort(function(a,b){return a-b}),a>b[0]&&a<b[1]},a.addListener=function(a,b,c){return"undefined"!=typeof a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c)},a.preventDefault=function(a){return a.preventDefault?a.preventDefault():a.returnValue=!1},a.getClip=function(a){return a.clipboardData?a.clipboardData.getData("Text"):window.clipboardData?window.clipboardData.getData("Text"):void 0},a.isDelKey=function(a){return 8===a||46===a||c&&127===a},a.isSpecialKey=function(a){var b={9:"tab",13:"enter",35:"end",36:"home",37:"leftarrow",38:"uparrow",39:"rightarrow",40:"downarrow",116:"F5"};return b[a]},a.isModifier=function(a){return a.ctrlKey||a.altKey||a.metaKey},a.forEach=function(a,b,c){if(a.hasOwnProperty("length"))for(var d=0,e=a.length;e>d&&b.call(c,a[d],d,a)!==!1;d++);else for(var f in a)if(a.hasOwnProperty(f)&&b.call(c,a[f],f,a)===!1)break},a}(),c=function(a,b){function c(c){var e=[],f=[];b.forEach(c,function(c){b.forEach(c,function(b,c){var g=a.parse(b),h=d(c);return e.push(h),f.push(g),!1})});var g=function(a){var c;return b.forEach(e,function(b,d){return b.test(a)?(c=d,!1):void 0}),void 0===c?null:f[c]};return{getPattern:g,patterns:f,matchers:e}}var d=function(a){return"*"===a?/.*/:new RegExp(a)};return c}(a,b),d=function(){var a={};return a.get=function(a){if("number"==typeof a.selectionStart)return{begin:a.selectionStart,end:a.selectionEnd};var b=document.selection.createRange();if(b&&b.parentElement()===a){var c=a.createTextRange(),d=a.createTextRange(),e=a.value.length;return c.moveToBookmark(b.getBookmark()),d.collapse(!1),c.compareEndPoints("StartToEnd",d)>-1?{begin:e,end:e}:{begin:-c.moveStart("character",-e),end:-c.moveEnd("character",-e)}}return{begin:0,end:0}},a.set=function(a,b){if("object"!=typeof b&&(b={begin:b,end:b}),a.setSelectionRange)a.focus(),a.setSelectionRange(b.begin,b.end);else if(a.createTextRange){var c=a.createTextRange();c.collapse(!0),c.moveEnd("character",b.end),c.moveStart("character",b.begin),c.select()}},a}(),e=function(a,b,c){function d(b,d){var f=this;if(f.el=b,!f.el)throw new TypeError("Must provide an existing element");if(f.opts=c.extend({},e,d),"undefined"!=typeof f.opts.pattern&&(f.opts.patterns=f._specFromSinglePattern(f.opts.pattern),delete f.opts.pattern),"undefined"==typeof f.opts.patterns)throw new TypeError("Must provide a pattern or array of patterns");f.patternMatcher=a(f.opts.patterns),f._updatePattern(),f.hldrs={},f.focus=0,c.addListener(f.el,"keydown",function(a){f._keyDown(a)}),c.addListener(f.el,"keypress",function(a){f._keyPress(a)}),c.addListener(f.el,"paste",function(a){f._paste(a)}),f.opts.persistent&&(f._processKey("",!1),f.el.blur(),c.addListener(f.el,"focus",function(a){f._focus(a)}),c.addListener(f.el,"click",function(a){f._focus(a)}),c.addListener(f.el,"touchstart",function(a){f._focus(a)}))}var e={persistent:!1,repeat:!1,placeholder:" "},f={9:/[0-9]/,a:/[A-Za-z]/,"*":/[A-Za-z0-9]/};return d.addInptType=function(a,b){f[a]=b},d.prototype.resetPattern=function(c){this.opts.patterns=c?this._specFromSinglePattern(c):this.opts.patterns,this.sel=b.get(this.el),this.val=this.el.value,this.delta=0,this._removeChars(),this.patternMatcher=a(this.opts.patterns);var d=this.patternMatcher.getPattern(this.val);this.mLength=d.mLength,this.chars=d.chars,this.inpts=d.inpts,this._processKey("",!1,!0)},d.prototype._updatePattern=function(){var a=this.patternMatcher.getPattern(this.val);a&&(this.mLength=a.mLength,this.chars=a.chars,this.inpts=a.inpts)},d.prototype._keyDown=function(a){var b=a.which||a.keyCode;return b&&c.isDelKey(b)?(this._processKey(null,b),c.preventDefault(a)):void 0},d.prototype._keyPress=function(a){var b,d;return a.which?b=a.which:(b=a.keyCode,d=c.isSpecialKey(b)),c.isDelKey(b)||d||c.isModifier(a)?void 0:(this._processKey(String.fromCharCode(b),!1),c.preventDefault(a))},d.prototype._paste=function(a){return this._processKey(c.getClip(a),!1),c.preventDefault(a)},d.prototype._focus=function(){var a=this;setTimeout(function(){var c=b.get(a.el),d=c.end>a.focus,e=0===c.end;(d||e)&&b.set(a.el,a.focus)},0)},d.prototype._processKey=function(a,d,e){if(this.sel=b.get(this.el),this.val=this.el.value,this.delta=0,this.sel.begin!==this.sel.end)this.delta=-1*Math.abs(this.sel.begin-this.sel.end),this.val=c.removeChars(this.val,this.sel.begin,this.sel.end);else if(d&&46===d)this._delete();else if(d&&this.sel.begin-1>=0){for(this.delta-=1;this.chars[this.focus-1];)this.delta--,this.focus--;this.val=c.removeChars(this.val,this.sel.end+this.delta,this.sel.end)}else if(d)return!0;d||(this.val=c.addChars(this.val,a,this.sel.begin),this.delta+=a.length),this._formatValue(e)},d.prototype._delete=function(){for(;this.chars[this.sel.begin];)this._nextPos();this.sel.begin<this.val.length&&(this._nextPos(),this.val=c.removeChars(this.val,this.sel.end-1,this.sel.end),this.delta=-1)},d.prototype._nextPos=function(){this.sel.end++,this.sel.begin++},d.prototype._formatValue=function(a){this.newPos=this.sel.end+this.delta,this._removeChars(),this._updatePattern(),this._validateInpts(),this._addChars(),this.el.value=this.val.substr(0,this.mLength),("undefined"==typeof a||a===!1)&&b.set(this.el,this.newPos)},d.prototype._removeChars=function(){this.sel.end>this.focus&&(this.delta+=this.sel.end-this.focus);for(var a=0,b=0;b<=this.mLength;b++){var d,e=this.chars[b],f=this.hldrs[b],g=b+a;g=b>=this.sel.begin?g+this.delta:g,d=this.val.charAt(g),(e&&e===d||f&&f===d)&&(this.val=c.removeChars(this.val,g,g+1),a--)}this.hldrs={},this.focus=this.val.length},d.prototype._validateInpts=function(){for(var a=0;a<this.val.length;a++){var b=this.inpts[a],d=!f[b],e=!d&&!f[b].test(this.val.charAt(a)),g=this.inpts[a];(d||e)&&g&&(this.val=c.removeChars(this.val,a,a+1),this.focusStart--,this.newPos--,this.delta--,a--)}},d.prototype._addChars=function(){if(this.opts.persistent){for(var a=0;a<=this.mLength;a++)this.val.charAt(a)||(this.val=c.addChars(this.val,this.opts.placeholder,a),this.hldrs[a]=this.opts.placeholder),this._addChar(a);for(;this.chars[this.focus];)this.focus++}else for(var b=0;b<=this.val.length;b++){if(this.delta<=0&&b===this.focus&&void 0===this.chars[b]||0===this.focus)return!0;this._addChar(b)}},d.prototype._addChar=function(a){var b=this.chars[a];return b?(c.isBetween(a,[this.sel.begin-1,this.newPos+1])&&(this.newPos++,this.delta++),a<=this.focus&&this.focus++,this.hldrs[a]&&(delete this.hldrs[a],this.hldrs[a+1]=this.opts.placeholder),void(this.val=c.addChars(this.val,b,a))):!0},d.prototype._specFromSinglePattern=function(a){return[{"*":a}]},d}(c,d,b);return e});
\ No newline at end of file
+!function(a,b){"function"==typeof define&&define.amd?define([],function(){return a.returnExportsGlobal=b()}):"object"==typeof exports?module.exports=b():a.Formatter=b()}(this,function(){var a=function(){var a={},b=4,c=new RegExp("{{([^}]+)}}","g"),d=function(a){for(var b,d=[];b=c.exec(a);)d.push(b);return d};return a.parse=function(a){var c={inpts:{},chars:{}},e=d(a),f=a.length,g=0,h=0,i=0,j=function(a){for(var d=a.length,e=0;d>e;e++)c.inpts[h]=a.charAt(e),h++;g++,i+=a.length+b-1};for(i;f>i;i++)g<e.length&&i===e[g].index?j(e[g][1]):c.chars[i-g*b]=a.charAt(i);return c.mLength=i-g*b,c},a}(),b=function(){{var a={};"undefined"!=typeof navigator?navigator.userAgent:null}return a.extend=function(a){for(var b=1;b<arguments.length;b++)for(var c in arguments[b])a[c]=arguments[b][c];return a},a.addChars=function(a,b,c){return a.substr(0,c)+b+a.substr(c,a.length)},a.removeChars=function(a,b,c){return a.substr(0,b)+a.substr(c,a.length)},a.isBetween=function(a,b){return b.sort(function(a,b){return a-b}),a>b[0]&&a<b[1]},a.addListener=function(a,b,c){return"undefined"!=typeof a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c)},a.preventDefault=function(a){return a.preventDefault?a.preventDefault():a.returnValue=!1},a.getClip=function(a){return a.clipboardData?a.clipboardData.getData("Text"):window.clipboardData?window.clipboardData.getData("Text"):void 0},a.getMatchingKey=function(a,b,c){for(var d in c){var e=c[d];if(a===e.which&&b===e.keyCode)return d}},a.isDelKeyDown=function(b,c){var d={backspace:{which:8,keyCode:8},"delete":{which:46,keyCode:46}};return a.getMatchingKey(b,c,d)},a.isDelKeyPress=function(b,c){var d={backspace:{which:8,keyCode:8,shiftKey:!1},"delete":{which:0,keyCode:46}};return a.getMatchingKey(b,c,d)},a.isSpecialKeyPress=function(b,c){var d={tab:{which:0,keyCode:9},enter:{which:13,keyCode:13},end:{which:0,keyCode:35},home:{which:0,keyCode:36},leftarrow:{which:0,keyCode:37},uparrow:{which:0,keyCode:38},rightarrow:{which:0,keyCode:39},downarrow:{which:0,keyCode:40},F5:{which:116,keyCode:116}};return a.getMatchingKey(b,c,d)},a.isModifier=function(a){return a.ctrlKey||a.altKey||a.metaKey},a.forEach=function(a,b,c){if(a.hasOwnProperty("length"))for(var d=0,e=a.length;e>d&&b.call(c,a[d],d,a)!==!1;d++);else for(var f in a)if(a.hasOwnProperty(f)&&b.call(c,a[f],f,a)===!1)break},a}(),c=function(a,b){function c(c){var e=[],f=[];b.forEach(c,function(c){b.forEach(c,function(b,c){var g=a.parse(b),h=d(c);return e.push(h),f.push(g),!1})});var g=function(a){var c;return b.forEach(e,function(b,d){return b.test(a)?(c=d,!1):void 0}),void 0===c?null:f[c]};return{getPattern:g,patterns:f,matchers:e}}var d=function(a){return"*"===a?/.*/:new RegExp(a)};return c}(a,b),d=function(){var a={};return a.get=function(a){if("number"==typeof a.selectionStart)return{begin:a.selectionStart,end:a.selectionEnd};var b=document.selection.createRange();if(b&&b.parentElement()===a){var c=a.createTextRange(),d=a.createTextRange(),e=a.value.length;return c.moveToBookmark(b.getBookmark()),d.collapse(!1),c.compareEndPoints("StartToEnd",d)>-1?{begin:e,end:e}:{begin:-c.moveStart("character",-e),end:-c.moveEnd("character",-e)}}return{begin:0,end:0}},a.set=function(a,b){if("object"!=typeof b&&(b={begin:b,end:b}),a.setSelectionRange)a.focus(),a.setSelectionRange(b.begin,b.end);else if(a.createTextRange){var c=a.createTextRange();c.collapse(!0),c.moveEnd("character",b.end),c.moveStart("character",b.begin),c.select()}},a}(),e=function(a,b,c){function d(b,d){var f=this;if(f.el=b,!f.el)throw new TypeError("Must provide an existing element");if(f.opts=c.extend({},e,d),"undefined"!=typeof f.opts.pattern&&(f.opts.patterns=f._specFromSinglePattern(f.opts.pattern),delete f.opts.pattern),"undefined"==typeof f.opts.patterns)throw new TypeError("Must provide a pattern or array of patterns");f.patternMatcher=a(f.opts.patterns),f._updatePattern(),f.hldrs={},f.focus=0,c.addListener(f.el,"keydown",function(a){f._keyDown(a)}),c.addListener(f.el,"keypress",function(a){f._keyPress(a)}),c.addListener(f.el,"paste",function(a){f._paste(a)}),f.opts.persistent&&(f._processKey("",!1),f.el.blur(),c.addListener(f.el,"focus",function(a){f._focus(a)}),c.addListener(f.el,"click",function(a){f._focus(a)}),c.addListener(f.el,"touchstart",function(a){f._focus(a)}))}var e={persistent:!1,repeat:!1,placeholder:" "},f={9:/[0-9]/,a:/[A-Za-z]/,"*":/[A-Za-z0-9]/};return d.addInptType=function(a,b){f[a]=b},d.prototype.resetPattern=function(c){this.opts.patterns=c?this._specFromSinglePattern(c):this.opts.patterns,this.sel=b.get(this.el),this.val=this.el.value,this.delta=0,this._removeChars(),this.patternMatcher=a(this.opts.patterns);var d=this.patternMatcher.getPattern(this.val);this.mLength=d.mLength,this.chars=d.chars,this.inpts=d.inpts,this._processKey("",!1,!0)},d.prototype._updatePattern=function(){var a=this.patternMatcher.getPattern(this.val);a&&(this.mLength=a.mLength,this.chars=a.chars,this.inpts=a.inpts)},d.prototype._keyDown=function(a){var b=a.which||a.keyCode;return b&&c.isDelKeyDown(a.which,a.keyCode)?(this._processKey(null,b),c.preventDefault(a)):void 0},d.prototype._keyPress=function(a){var b,d;return b=a.which||a.keyCode,d=c.isSpecialKeyPress(a.which,a.keyCode),c.isDelKeyPress(a.which,a.keyCode)||d||c.isModifier(a)?void 0:(this._processKey(String.fromCharCode(b),!1),c.preventDefault(a))},d.prototype._paste=function(a){return this._processKey(c.getClip(a),!1),c.preventDefault(a)},d.prototype._focus=function(){var a=this;setTimeout(function(){var c=b.get(a.el),d=c.end>a.focus,e=0===c.end;(d||e)&&b.set(a.el,a.focus)},0)},d.prototype._processKey=function(a,d,e){if(this.sel=b.get(this.el),this.val=this.el.value,this.delta=0,this.sel.begin!==this.sel.end)this.delta=-1*Math.abs(this.sel.begin-this.sel.end),this.val=c.removeChars(this.val,this.sel.begin,this.sel.end);else if(d&&46===d)this._delete();else if(d&&this.sel.begin-1>=0)this.val=c.removeChars(this.val,this.sel.end-1,this.sel.end),this.delta-=1;else if(d)return!0;d||(this.val=c.addChars(this.val,a,this.sel.begin),this.delta+=a.length),this._formatValue(e)},d.prototype._delete=function(){for(;this.chars[this.sel.begin];)this._nextPos();this.sel.begin<this.val.length&&(this._nextPos(),this.val=c.removeChars(this.val,this.sel.end-1,this.sel.end),this.delta=-1)},d.prototype._nextPos=function(){this.sel.end++,this.sel.begin++},d.prototype._formatValue=function(a){this.newPos=this.sel.end+this.delta,this._removeChars(),this._updatePattern(),this._validateInpts(),this._addChars(),this.el.value=this.val.substr(0,this.mLength),("undefined"==typeof a||a===!1)&&b.set(this.el,this.newPos)},d.prototype._removeChars=function(){this.sel.end>this.focus&&(this.delta+=this.sel.end-this.focus);for(var a=0,b=0;b<=this.mLength;b++){var d,e=this.chars[b],f=this.hldrs[b],g=b+a;g=b>=this.sel.begin?g+this.delta:g,d=this.val.charAt(g),(e&&e===d||f&&f===d)&&(this.val=c.removeChars(this.val,g,g+1),a--)}this.hldrs={},this.focus=this.val.length},d.prototype._validateInpts=function(){for(var a=0;a<this.val.length;a++){var b=this.inpts[a],d=!f[b],e=!d&&!f[b].test(this.val.charAt(a)),g=this.inpts[a];(d||e)&&g&&(this.val=c.removeChars(this.val,a,a+1),this.focusStart--,this.newPos--,this.delta--,a--)}},d.prototype._addChars=function(){if(this.opts.persistent){for(var a=0;a<=this.mLength;a++)this.val.charAt(a)||(this.val=c.addChars(this.val,this.opts.placeholder,a),this.hldrs[a]=this.opts.placeholder),this._addChar(a);for(;this.chars[this.focus];)this.focus++}else for(var b=0;b<=this.val.length;b++){if(this.delta<=0&&b===this.focus)return!0;this._addChar(b)}},d.prototype._addChar=function(a){var b=this.chars[a];return b?(c.isBetween(a,[this.sel.begin-1,this.newPos+1])&&(this.newPos++,this.delta++),a<=this.focus&&this.focus++,this.hldrs[a]&&(delete this.hldrs[a],this.hldrs[a+1]=this.opts.placeholder),void(this.val=c.addChars(this.val,b,a))):!0},d.prototype._specFromSinglePattern=function(a){return[{"*":a}]},d}(c,d,b);return e});
\ No newline at end of file
diff --git a/javascripts/jquery.formatter.js b/javascripts/jquery.formatter.js
index fdd3de0..1f65d0d 100644
--- a/javascripts/jquery.formatter.js
+++ b/javascripts/jquery.formatter.js
@@ -1,5 +1,5 @@
 /*!
- * v0.0.9
+ * v0.1.3
  * Copyright (c) 2014 First Opinion
  * formatter.js is open sourced under the MIT license.
  *
@@ -102,7 +102,7 @@ var utils = function () {
     // Define module
     var utils = {};
     // Useragent info for keycode handling
-    var uAgent = typeof navigator !== 'undefined' ? navigator.userAgent : null, iPhone = /iphone/i.test(uAgent);
+    var uAgent = typeof navigator !== 'undefined' ? navigator.userAgent : null;
     //
     // Shallow copy properties from n objects to destObj
     //
@@ -160,28 +160,110 @@ var utils = function () {
       }
     };
     //
-    // Returns true/false if k is a del key
+    // Loop over object and checking for matching properties
     //
-    utils.isDelKey = function (k) {
-      return k === 8 || k === 46 || iPhone && k === 127;
+    utils.getMatchingKey = function (which, keyCode, keys) {
+      // Loop over and return if matched.
+      for (var k in keys) {
+        var key = keys[k];
+        if (which === key.which && keyCode === key.keyCode) {
+          return k;
+        }
+      }
     };
     //
-    // Returns true/false if k is an arrow key
+    // Returns true/false if k is a del keyDown
     //
-    utils.isSpecialKey = function (k) {
-      var codes = {
-          '9': 'tab',
-          '13': 'enter',
-          '35': 'end',
-          '36': 'home',
-          '37': 'leftarrow',
-          '38': 'uparrow',
-          '39': 'rightarrow',
-          '40': 'downarrow',
-          '116': 'F5'
+    utils.isDelKeyDown = function (which, keyCode) {
+      var keys = {
+          'backspace': {
+            'which': 8,
+            'keyCode': 8
+          },
+          'delete': {
+            'which': 46,
+            'keyCode': 46
+          }
         };
-      // If del or special key
-      return codes[k];
+      return utils.getMatchingKey(which, keyCode, keys);
+    };
+    //
+    // Returns true/false if k is a del keyPress
+    //
+    utils.isDelKeyPress = function (which, keyCode) {
+      var keys = {
+          'backspace': {
+            'which': 8,
+            'keyCode': 8,
+            'shiftKey': false
+          },
+          'delete': {
+            'which': 0,
+            'keyCode': 46
+          }
+        };
+      return utils.getMatchingKey(which, keyCode, keys);
+    };
+    // //
+    // // Determine if keydown relates to specialKey
+    // //
+    // utils.isSpecialKeyDown = function (which, keyCode) {
+    //   var keys = {
+    //     'tab': { 'which': 9, 'keyCode': 9 },
+    //     'enter': { 'which': 13, 'keyCode': 13 },
+    //     'end': { 'which': 35, 'keyCode': 35 },
+    //     'home': { 'which': 36, 'keyCode': 36 },
+    //     'leftarrow': { 'which': 37, 'keyCode': 37 },
+    //     'uparrow': { 'which': 38, 'keyCode': 38 },
+    //     'rightarrow': { 'which': 39, 'keyCode': 39 },
+    //     'downarrow': { 'which': 40, 'keyCode': 40 },
+    //     'F5': { 'which': 116, 'keyCode': 116 }
+    //   };
+    //   return utils.getMatchingKey(which, keyCode, keys);
+    // };
+    //
+    // Determine if keypress relates to specialKey
+    //
+    utils.isSpecialKeyPress = function (which, keyCode) {
+      var keys = {
+          'tab': {
+            'which': 0,
+            'keyCode': 9
+          },
+          'enter': {
+            'which': 13,
+            'keyCode': 13
+          },
+          'end': {
+            'which': 0,
+            'keyCode': 35
+          },
+          'home': {
+            'which': 0,
+            'keyCode': 36
+          },
+          'leftarrow': {
+            'which': 0,
+            'keyCode': 37
+          },
+          'uparrow': {
+            'which': 0,
+            'keyCode': 38
+          },
+          'rightarrow': {
+            'which': 0,
+            'keyCode': 39
+          },
+          'downarrow': {
+            'which': 0,
+            'keyCode': 40
+          },
+          'F5': {
+            'which': 116,
+            'keyCode': 116
+          }
+        };
+      return utils.getMatchingKey(which, keyCode, keys);
     };
     //
     // Returns true/false if modifier key is held down
@@ -481,7 +563,7 @@ var formatter = function (patternMatcher, inptSel, utils) {
       // The first thing we need is the character code
       var k = evt.which || evt.keyCode;
       // If delete key
-      if (k && utils.isDelKey(k)) {
+      if (k && utils.isDelKeyDown(evt.which, evt.keyCode)) {
         // Process the keyCode and prevent default
         this._processKey(null, k);
         return utils.preventDefault(evt);
@@ -497,14 +579,10 @@ var formatter = function (patternMatcher, inptSel, utils) {
       var k, isSpecial;
       // Mozilla will trigger on special keys and assign the the value 0
       // We want to use that 0 rather than the keyCode it assigns.
-      if (evt.which) {
-        k = evt.which;
-      } else {
-        k = evt.keyCode;
-        isSpecial = utils.isSpecialKey(k);
-      }
+      k = evt.which || evt.keyCode;
+      isSpecial = utils.isSpecialKeyPress(evt.which, evt.keyCode);
       // Process the keyCode and prevent default
-      if (!utils.isDelKey(k) && !isSpecial && !utils.isModifier(evt)) {
+      if (!utils.isDelKeyPress(evt.which, evt.keyCode) && !isSpecial && !utils.isModifier(evt)) {
         this._processKey(String.fromCharCode(k), false);
         return utils.preventDefault(evt);
       }
@@ -540,7 +618,7 @@ var formatter = function (patternMatcher, inptSel, utils) {
     // @private
     // Using the provided key information, alter el value.
     //
-    Formatter.prototype._processKey = function (chars, delKey, ingoreCaret) {
+    Formatter.prototype._processKey = function (chars, delKey, ignoreCaret) {
       // Get current state
       this.sel = inptSel.get(this.el);
       this.val = this.el.value;
@@ -554,13 +632,8 @@ var formatter = function (patternMatcher, inptSel, utils) {
         this._delete();
       } else if (delKey && this.sel.begin - 1 >= 0) {
         // Always have a delta of at least -1 for the character being deleted.
+        this.val = utils.removeChars(this.val, this.sel.end - 1, this.sel.end);
         this.delta -= 1;
-        // Count number of additional format chars to be deleted. (A group of multiple format chars should be deleted like one value char.)
-        while (this.chars[this.focus - 1]) {
-          this.delta--;
-          this.focus--;
-        }
-        this.val = utils.removeChars(this.val, this.sel.end + this.delta, this.sel.end);
       } else if (delKey) {
         return true;
       }
@@ -571,7 +644,7 @@ var formatter = function (patternMatcher, inptSel, utils) {
         this.delta += chars.length;
       }
       // Format el.value (also handles updating caret position)
-      this._formatValue(ingoreCaret);
+      this._formatValue(ignoreCaret);
     };
     //
     // @private
@@ -692,10 +765,11 @@ var formatter = function (patternMatcher, inptSel, utils) {
           this.focus++;
         }
       } else {
-        // Avoid caching val.length and this.focus, as they may change in _addChar.
+        // Avoid caching val.length, as they may change in _addChar.
         for (var j = 0; j <= this.val.length; j++) {
-          // When moving backwards, i.e. delting characters, don't add format characters past focus point.
-          if (this.delta <= 0 && j === this.focus && this.chars[j] === undefined || this.focus === 0) {
+          // When moving backwards there are some race conditions where we
+          // dont want to add the character
+          if (this.delta <= 0 && j === this.focus) {
             return true;
           }
           // Place character in current position of the formatted string.
diff --git a/javascripts/jquery.formatter.min.js b/javascripts/jquery.formatter.min.js
index 9418837..7001b39 100644
--- a/javascripts/jquery.formatter.min.js
+++ b/javascripts/jquery.formatter.min.js
@@ -1 +1 @@
-!function(a,b){"function"==typeof define&&define.amd?define(["jQuery"],b):b("object"==typeof exports?require("jQuery"):a.jQuery)}(this,function(){var a=function(){var a={},b=4,c=new RegExp("{{([^}]+)}}","g"),d=function(a){for(var b,d=[];b=c.exec(a);)d.push(b);return d};return a.parse=function(a){var c={inpts:{},chars:{}},e=d(a),f=a.length,g=0,h=0,i=0,j=function(a){for(var d=a.length,e=0;d>e;e++)c.inpts[h]=a.charAt(e),h++;g++,i+=a.length+b-1};for(i;f>i;i++)g<e.length&&i===e[g].index?j(e[g][1]):c.chars[i-g*b]=a.charAt(i);return c.mLength=i-g*b,c},a}(),b=function(){var a={},b="undefined"!=typeof navigator?navigator.userAgent:null,c=/iphone/i.test(b);return a.extend=function(a){for(var b=1;b<arguments.length;b++)for(var c in arguments[b])a[c]=arguments[b][c];return a},a.addChars=function(a,b,c){return a.substr(0,c)+b+a.substr(c,a.length)},a.removeChars=function(a,b,c){return a.substr(0,b)+a.substr(c,a.length)},a.isBetween=function(a,b){return b.sort(function(a,b){return a-b}),a>b[0]&&a<b[1]},a.addListener=function(a,b,c){return"undefined"!=typeof a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c)},a.preventDefault=function(a){return a.preventDefault?a.preventDefault():a.returnValue=!1},a.getClip=function(a){return a.clipboardData?a.clipboardData.getData("Text"):window.clipboardData?window.clipboardData.getData("Text"):void 0},a.isDelKey=function(a){return 8===a||46===a||c&&127===a},a.isSpecialKey=function(a){var b={9:"tab",13:"enter",35:"end",36:"home",37:"leftarrow",38:"uparrow",39:"rightarrow",40:"downarrow",116:"F5"};return b[a]},a.isModifier=function(a){return a.ctrlKey||a.altKey||a.metaKey},a.forEach=function(a,b,c){if(a.hasOwnProperty("length"))for(var d=0,e=a.length;e>d&&b.call(c,a[d],d,a)!==!1;d++);else for(var f in a)if(a.hasOwnProperty(f)&&b.call(c,a[f],f,a)===!1)break},a}(),c=function(a,b){function c(c){var e=[],f=[];b.forEach(c,function(c){b.forEach(c,function(b,c){var g=a.parse(b),h=d(c);return e.push(h),f.push(g),!1})});var g=function(a){var c;return b.forEach(e,function(b,d){return b.test(a)?(c=d,!1):void 0}),void 0===c?null:f[c]};return{getPattern:g,patterns:f,matchers:e}}var d=function(a){return"*"===a?/.*/:new RegExp(a)};return c}(a,b),d=function(){var a={};return a.get=function(a){if("number"==typeof a.selectionStart)return{begin:a.selectionStart,end:a.selectionEnd};var b=document.selection.createRange();if(b&&b.parentElement()===a){var c=a.createTextRange(),d=a.createTextRange(),e=a.value.length;return c.moveToBookmark(b.getBookmark()),d.collapse(!1),c.compareEndPoints("StartToEnd",d)>-1?{begin:e,end:e}:{begin:-c.moveStart("character",-e),end:-c.moveEnd("character",-e)}}return{begin:0,end:0}},a.set=function(a,b){if("object"!=typeof b&&(b={begin:b,end:b}),a.setSelectionRange)a.focus(),a.setSelectionRange(b.begin,b.end);else if(a.createTextRange){var c=a.createTextRange();c.collapse(!0),c.moveEnd("character",b.end),c.moveStart("character",b.begin),c.select()}},a}(),e=function(a,b,c){function d(b,d){var f=this;if(f.el=b,!f.el)throw new TypeError("Must provide an existing element");if(f.opts=c.extend({},e,d),"undefined"!=typeof f.opts.pattern&&(f.opts.patterns=f._specFromSinglePattern(f.opts.pattern),delete f.opts.pattern),"undefined"==typeof f.opts.patterns)throw new TypeError("Must provide a pattern or array of patterns");f.patternMatcher=a(f.opts.patterns),f._updatePattern(),f.hldrs={},f.focus=0,c.addListener(f.el,"keydown",function(a){f._keyDown(a)}),c.addListener(f.el,"keypress",function(a){f._keyPress(a)}),c.addListener(f.el,"paste",function(a){f._paste(a)}),f.opts.persistent&&(f._processKey("",!1),f.el.blur(),c.addListener(f.el,"focus",function(a){f._focus(a)}),c.addListener(f.el,"click",function(a){f._focus(a)}),c.addListener(f.el,"touchstart",function(a){f._focus(a)}))}var e={persistent:!1,repeat:!1,placeholder:" "},f={9:/[0-9]/,a:/[A-Za-z]/,"*":/[A-Za-z0-9]/};return d.addInptType=function(a,b){f[a]=b},d.prototype.resetPattern=function(c){this.opts.patterns=c?this._specFromSinglePattern(c):this.opts.patterns,this.sel=b.get(this.el),this.val=this.el.value,this.delta=0,this._removeChars(),this.patternMatcher=a(this.opts.patterns);var d=this.patternMatcher.getPattern(this.val);this.mLength=d.mLength,this.chars=d.chars,this.inpts=d.inpts,this._processKey("",!1,!0)},d.prototype._updatePattern=function(){var a=this.patternMatcher.getPattern(this.val);a&&(this.mLength=a.mLength,this.chars=a.chars,this.inpts=a.inpts)},d.prototype._keyDown=function(a){var b=a.which||a.keyCode;return b&&c.isDelKey(b)?(this._processKey(null,b),c.preventDefault(a)):void 0},d.prototype._keyPress=function(a){var b,d;return a.which?b=a.which:(b=a.keyCode,d=c.isSpecialKey(b)),c.isDelKey(b)||d||c.isModifier(a)?void 0:(this._processKey(String.fromCharCode(b),!1),c.preventDefault(a))},d.prototype._paste=function(a){return this._processKey(c.getClip(a),!1),c.preventDefault(a)},d.prototype._focus=function(){var a=this;setTimeout(function(){var c=b.get(a.el),d=c.end>a.focus,e=0===c.end;(d||e)&&b.set(a.el,a.focus)},0)},d.prototype._processKey=function(a,d,e){if(this.sel=b.get(this.el),this.val=this.el.value,this.delta=0,this.sel.begin!==this.sel.end)this.delta=-1*Math.abs(this.sel.begin-this.sel.end),this.val=c.removeChars(this.val,this.sel.begin,this.sel.end);else if(d&&46===d)this._delete();else if(d&&this.sel.begin-1>=0){for(this.delta-=1;this.chars[this.focus-1];)this.delta--,this.focus--;this.val=c.removeChars(this.val,this.sel.end+this.delta,this.sel.end)}else if(d)return!0;d||(this.val=c.addChars(this.val,a,this.sel.begin),this.delta+=a.length),this._formatValue(e)},d.prototype._delete=function(){for(;this.chars[this.sel.begin];)this._nextPos();this.sel.begin<this.val.length&&(this._nextPos(),this.val=c.removeChars(this.val,this.sel.end-1,this.sel.end),this.delta=-1)},d.prototype._nextPos=function(){this.sel.end++,this.sel.begin++},d.prototype._formatValue=function(a){this.newPos=this.sel.end+this.delta,this._removeChars(),this._updatePattern(),this._validateInpts(),this._addChars(),this.el.value=this.val.substr(0,this.mLength),("undefined"==typeof a||a===!1)&&b.set(this.el,this.newPos)},d.prototype._removeChars=function(){this.sel.end>this.focus&&(this.delta+=this.sel.end-this.focus);for(var a=0,b=0;b<=this.mLength;b++){var d,e=this.chars[b],f=this.hldrs[b],g=b+a;g=b>=this.sel.begin?g+this.delta:g,d=this.val.charAt(g),(e&&e===d||f&&f===d)&&(this.val=c.removeChars(this.val,g,g+1),a--)}this.hldrs={},this.focus=this.val.length},d.prototype._validateInpts=function(){for(var a=0;a<this.val.length;a++){var b=this.inpts[a],d=!f[b],e=!d&&!f[b].test(this.val.charAt(a)),g=this.inpts[a];(d||e)&&g&&(this.val=c.removeChars(this.val,a,a+1),this.focusStart--,this.newPos--,this.delta--,a--)}},d.prototype._addChars=function(){if(this.opts.persistent){for(var a=0;a<=this.mLength;a++)this.val.charAt(a)||(this.val=c.addChars(this.val,this.opts.placeholder,a),this.hldrs[a]=this.opts.placeholder),this._addChar(a);for(;this.chars[this.focus];)this.focus++}else for(var b=0;b<=this.val.length;b++){if(this.delta<=0&&b===this.focus&&void 0===this.chars[b]||0===this.focus)return!0;this._addChar(b)}},d.prototype._addChar=function(a){var b=this.chars[a];return b?(c.isBetween(a,[this.sel.begin-1,this.newPos+1])&&(this.newPos++,this.delta++),a<=this.focus&&this.focus++,this.hldrs[a]&&(delete this.hldrs[a],this.hldrs[a+1]=this.opts.placeholder),void(this.val=c.addChars(this.val,b,a))):!0},d.prototype._specFromSinglePattern=function(a){return[{"*":a}]},d}(c,d,b),f="formatter";$.fn[f]=function(a){return"object"==typeof a&&this.each(function(){$.data(this,"plugin_"+f)||$.data(this,"plugin_"+f,new e(this,a))}),this.resetPattern=function(a){return this.each(function(){var b=$.data(this,"plugin_"+f);b&&b.resetPattern(a)}),this},this},$.fn[f].addInptType=function(a,b){e.addInptType(a,b)}});
\ No newline at end of file
+!function(a,b){"function"==typeof define&&define.amd?define(["jQuery"],b):b("object"==typeof exports?require("jQuery"):a.jQuery)}(this,function(){var a=function(){var a={},b=4,c=new RegExp("{{([^}]+)}}","g"),d=function(a){for(var b,d=[];b=c.exec(a);)d.push(b);return d};return a.parse=function(a){var c={inpts:{},chars:{}},e=d(a),f=a.length,g=0,h=0,i=0,j=function(a){for(var d=a.length,e=0;d>e;e++)c.inpts[h]=a.charAt(e),h++;g++,i+=a.length+b-1};for(i;f>i;i++)g<e.length&&i===e[g].index?j(e[g][1]):c.chars[i-g*b]=a.charAt(i);return c.mLength=i-g*b,c},a}(),b=function(){{var a={};"undefined"!=typeof navigator?navigator.userAgent:null}return a.extend=function(a){for(var b=1;b<arguments.length;b++)for(var c in arguments[b])a[c]=arguments[b][c];return a},a.addChars=function(a,b,c){return a.substr(0,c)+b+a.substr(c,a.length)},a.removeChars=function(a,b,c){return a.substr(0,b)+a.substr(c,a.length)},a.isBetween=function(a,b){return b.sort(function(a,b){return a-b}),a>b[0]&&a<b[1]},a.addListener=function(a,b,c){return"undefined"!=typeof a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c)},a.preventDefault=function(a){return a.preventDefault?a.preventDefault():a.returnValue=!1},a.getClip=function(a){return a.clipboardData?a.clipboardData.getData("Text"):window.clipboardData?window.clipboardData.getData("Text"):void 0},a.getMatchingKey=function(a,b,c){for(var d in c){var e=c[d];if(a===e.which&&b===e.keyCode)return d}},a.isDelKeyDown=function(b,c){var d={backspace:{which:8,keyCode:8},"delete":{which:46,keyCode:46}};return a.getMatchingKey(b,c,d)},a.isDelKeyPress=function(b,c){var d={backspace:{which:8,keyCode:8,shiftKey:!1},"delete":{which:0,keyCode:46}};return a.getMatchingKey(b,c,d)},a.isSpecialKeyPress=function(b,c){var d={tab:{which:0,keyCode:9},enter:{which:13,keyCode:13},end:{which:0,keyCode:35},home:{which:0,keyCode:36},leftarrow:{which:0,keyCode:37},uparrow:{which:0,keyCode:38},rightarrow:{which:0,keyCode:39},downarrow:{which:0,keyCode:40},F5:{which:116,keyCode:116}};return a.getMatchingKey(b,c,d)},a.isModifier=function(a){return a.ctrlKey||a.altKey||a.metaKey},a.forEach=function(a,b,c){if(a.hasOwnProperty("length"))for(var d=0,e=a.length;e>d&&b.call(c,a[d],d,a)!==!1;d++);else for(var f in a)if(a.hasOwnProperty(f)&&b.call(c,a[f],f,a)===!1)break},a}(),c=function(a,b){function c(c){var e=[],f=[];b.forEach(c,function(c){b.forEach(c,function(b,c){var g=a.parse(b),h=d(c);return e.push(h),f.push(g),!1})});var g=function(a){var c;return b.forEach(e,function(b,d){return b.test(a)?(c=d,!1):void 0}),void 0===c?null:f[c]};return{getPattern:g,patterns:f,matchers:e}}var d=function(a){return"*"===a?/.*/:new RegExp(a)};return c}(a,b),d=function(){var a={};return a.get=function(a){if("number"==typeof a.selectionStart)return{begin:a.selectionStart,end:a.selectionEnd};var b=document.selection.createRange();if(b&&b.parentElement()===a){var c=a.createTextRange(),d=a.createTextRange(),e=a.value.length;return c.moveToBookmark(b.getBookmark()),d.collapse(!1),c.compareEndPoints("StartToEnd",d)>-1?{begin:e,end:e}:{begin:-c.moveStart("character",-e),end:-c.moveEnd("character",-e)}}return{begin:0,end:0}},a.set=function(a,b){if("object"!=typeof b&&(b={begin:b,end:b}),a.setSelectionRange)a.focus(),a.setSelectionRange(b.begin,b.end);else if(a.createTextRange){var c=a.createTextRange();c.collapse(!0),c.moveEnd("character",b.end),c.moveStart("character",b.begin),c.select()}},a}(),e=function(a,b,c){function d(b,d){var f=this;if(f.el=b,!f.el)throw new TypeError("Must provide an existing element");if(f.opts=c.extend({},e,d),"undefined"!=typeof f.opts.pattern&&(f.opts.patterns=f._specFromSinglePattern(f.opts.pattern),delete f.opts.pattern),"undefined"==typeof f.opts.patterns)throw new TypeError("Must provide a pattern or array of patterns");f.patternMatcher=a(f.opts.patterns),f._updatePattern(),f.hldrs={},f.focus=0,c.addListener(f.el,"keydown",function(a){f._keyDown(a)}),c.addListener(f.el,"keypress",function(a){f._keyPress(a)}),c.addListener(f.el,"paste",function(a){f._paste(a)}),f.opts.persistent&&(f._processKey("",!1),f.el.blur(),c.addListener(f.el,"focus",function(a){f._focus(a)}),c.addListener(f.el,"click",function(a){f._focus(a)}),c.addListener(f.el,"touchstart",function(a){f._focus(a)}))}var e={persistent:!1,repeat:!1,placeholder:" "},f={9:/[0-9]/,a:/[A-Za-z]/,"*":/[A-Za-z0-9]/};return d.addInptType=function(a,b){f[a]=b},d.prototype.resetPattern=function(c){this.opts.patterns=c?this._specFromSinglePattern(c):this.opts.patterns,this.sel=b.get(this.el),this.val=this.el.value,this.delta=0,this._removeChars(),this.patternMatcher=a(this.opts.patterns);var d=this.patternMatcher.getPattern(this.val);this.mLength=d.mLength,this.chars=d.chars,this.inpts=d.inpts,this._processKey("",!1,!0)},d.prototype._updatePattern=function(){var a=this.patternMatcher.getPattern(this.val);a&&(this.mLength=a.mLength,this.chars=a.chars,this.inpts=a.inpts)},d.prototype._keyDown=function(a){var b=a.which||a.keyCode;return b&&c.isDelKeyDown(a.which,a.keyCode)?(this._processKey(null,b),c.preventDefault(a)):void 0},d.prototype._keyPress=function(a){var b,d;return b=a.which||a.keyCode,d=c.isSpecialKeyPress(a.which,a.keyCode),c.isDelKeyPress(a.which,a.keyCode)||d||c.isModifier(a)?void 0:(this._processKey(String.fromCharCode(b),!1),c.preventDefault(a))},d.prototype._paste=function(a){return this._processKey(c.getClip(a),!1),c.preventDefault(a)},d.prototype._focus=function(){var a=this;setTimeout(function(){var c=b.get(a.el),d=c.end>a.focus,e=0===c.end;(d||e)&&b.set(a.el,a.focus)},0)},d.prototype._processKey=function(a,d,e){if(this.sel=b.get(this.el),this.val=this.el.value,this.delta=0,this.sel.begin!==this.sel.end)this.delta=-1*Math.abs(this.sel.begin-this.sel.end),this.val=c.removeChars(this.val,this.sel.begin,this.sel.end);else if(d&&46===d)this._delete();else if(d&&this.sel.begin-1>=0)this.val=c.removeChars(this.val,this.sel.end-1,this.sel.end),this.delta-=1;else if(d)return!0;d||(this.val=c.addChars(this.val,a,this.sel.begin),this.delta+=a.length),this._formatValue(e)},d.prototype._delete=function(){for(;this.chars[this.sel.begin];)this._nextPos();this.sel.begin<this.val.length&&(this._nextPos(),this.val=c.removeChars(this.val,this.sel.end-1,this.sel.end),this.delta=-1)},d.prototype._nextPos=function(){this.sel.end++,this.sel.begin++},d.prototype._formatValue=function(a){this.newPos=this.sel.end+this.delta,this._removeChars(),this._updatePattern(),this._validateInpts(),this._addChars(),this.el.value=this.val.substr(0,this.mLength),("undefined"==typeof a||a===!1)&&b.set(this.el,this.newPos)},d.prototype._removeChars=function(){this.sel.end>this.focus&&(this.delta+=this.sel.end-this.focus);for(var a=0,b=0;b<=this.mLength;b++){var d,e=this.chars[b],f=this.hldrs[b],g=b+a;g=b>=this.sel.begin?g+this.delta:g,d=this.val.charAt(g),(e&&e===d||f&&f===d)&&(this.val=c.removeChars(this.val,g,g+1),a--)}this.hldrs={},this.focus=this.val.length},d.prototype._validateInpts=function(){for(var a=0;a<this.val.length;a++){var b=this.inpts[a],d=!f[b],e=!d&&!f[b].test(this.val.charAt(a)),g=this.inpts[a];(d||e)&&g&&(this.val=c.removeChars(this.val,a,a+1),this.focusStart--,this.newPos--,this.delta--,a--)}},d.prototype._addChars=function(){if(this.opts.persistent){for(var a=0;a<=this.mLength;a++)this.val.charAt(a)||(this.val=c.addChars(this.val,this.opts.placeholder,a),this.hldrs[a]=this.opts.placeholder),this._addChar(a);for(;this.chars[this.focus];)this.focus++}else for(var b=0;b<=this.val.length;b++){if(this.delta<=0&&b===this.focus)return!0;this._addChar(b)}},d.prototype._addChar=function(a){var b=this.chars[a];return b?(c.isBetween(a,[this.sel.begin-1,this.newPos+1])&&(this.newPos++,this.delta++),a<=this.focus&&this.focus++,this.hldrs[a]&&(delete this.hldrs[a],this.hldrs[a+1]=this.opts.placeholder),void(this.val=c.addChars(this.val,b,a))):!0},d.prototype._specFromSinglePattern=function(a){return[{"*":a}]},d}(c,d,b),f="formatter";$.fn[f]=function(a){return"object"==typeof a&&this.each(function(){$.data(this,"plugin_"+f)||$.data(this,"plugin_"+f,new e(this,a))}),this.resetPattern=function(a){return this.each(function(){var b=$.data(this,"plugin_"+f);b&&b.resetPattern(a)}),this},this},$.fn[f].addInptType=function(a,b){e.addInptType(a,b)}});
\ No newline at end of file
