/*
  Character mask for jQuery.
  https://github.com/sobrinho/jquery.singlemask

  Copyright (c) 2011-2013 Gabriel Sobrinho (http://gabrielsobrinho.com/).
  Released under the MIT license
*/
(function ($) {
  function getPasteEvent() {
    var el = document.createElement('input'),

    name = 'onpaste';
    el.setAttribute(name, '');
    return (typeof el[name] === 'function') ? 'paste' : 'input';
  }

  var pasteEventName = getPasteEvent();

  $.fn.singlemask = function (mask) {
    $(this).keydown(function (event) {
      var key = event.keyCode;

      if (key < 16 || (key > 16 && key < 32) || (key > 32 && key < 41)) {
        return;
      }

      return String.fromCharCode(key).match(mask);
    }).bind(pasteEventName, function () {
      this.value = $.grep(this.value, function (character) {
        return character.match(mask);
      }).join('');
    });
  }
})(jQuery);

/*
  Character mask for jQuery.
  https://github.com/sobrinho/jquery.singlemask

  Copyright (c) 2011-2013 Gabriel Sobrinho (http://gabrielsobrinho.com/).
  Released under the MIT license
*/
(function ($) {
  function getPasteEvent() {
    var el = document.createElement('input'),

    name = 'onpaste';
    el.setAttribute(name, '');
    return (typeof el[name] === 'function') ? 'paste' : 'input';
  }

  var pasteEventName = getPasteEvent();

  $.fn.singlemask = function (mask) {
    $(this).keydown(function (event) {
      var key = event.keyCode;

      if (key < 16 || (key > 16 && key < 32) || (key > 32 && key < 41)) {
        return;
      }

      // Numpad key numbers starts on 96 (0) and ends on 105 (9)
      // Somehow the String.fromCharCode doesn't knows that
      // Subtracting 48 we have the 'standard' number code
      if (key >= 96 && key <= 105) {
        key = key - 48;
      }

      return String.fromCharCode(key).match(mask);
    }).bind(pasteEventName, function () {
      this.value = $.grep(this.value, function (character) {
        return character.match(mask);
      }).join('');
    });
  }
})(jQuery);

Fix problem when using the numpad
Fix problem when using the numpad

The numpad numbers' code are different from the standard numbers. The
code number starts in 96 (number 0) and ends in 105 (number 9).

The problem is in the String.fromCharCode function because it doesn't
recognize the numpad code numbers.

To fix that this commit was made to calculate the 'correct' key code to
be used in the String.fromCharCode function.

Keyboard keys code:
http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
