Número Decimal con Millares (Español)

Plugin para campo numérico con el separador de millares con un punto, y el separador decimal es una coma.

by Yolanda Robles

HTML

<input class="numeric" id="txtNum" value="8" />

JavaScript

/**********************************************************************/
/**********************************************************************/
/*********************    PLUGIN   ************************************/
/**********************************************************************/
(function ($) {
    /*
     * Plugin numérico para meter los millares, y que el separador decimal sea
     * la coma en lugar del punto.
     */
    $.fn.numeric = function (config, callback) {
        if (typeof config === 'boolean') {
            config = {
                decimal: config
            };
        }
        config = config || {};
        // if config.negative undefined, set to true (default is to allow negative numbers)
        if (typeof config.negative == "undefined") config.negative = true;
        // set decimal point
        var decimal = (config.decimal === false) ? "" : config.decimal || ".";
        // allow negatives
        var negative = (config.negative === true) ? true : false;
        // callback function
        var callback = typeof callback == "function" ? callback : function () {};
        // set data and methods
        return this.data("numeric.decimal", decimal).data("numeric.negative", negative).data("numeric.callback", callback).keypress($.fn.numeric.keypress).keyup($.fn.numeric.keyup).blur($.fn.numeric.blur);
    }

    $.fn.numeric.keypress = function (e) {
        // get decimal character and determine if negatives are allowed
        var decimal = $.data(this, "numeric.decimal");
        var negative = $.data(this, "numeric.negative");
        // get the key that was pressed
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        // allow enter/return key (only when in an input box)
        if (key == 13 && this.nodeName.toLowerCase() == "input") {
            return true;
        } else if (key == 13) {
            return false;
        }
        var allow = false;
        // allow Ctrl+A
        if ((e.ctrlKey...