Source: controls/Validator/NumericValidator.js

/**
 * @requirefiles {controls/Validator/Validator.js}
 */

/**
 * The NumericValidator class provides for validation of numeric values.
 * @class NumericValidator
 * @extends Validator
 */
function NumericValidator() { }

/**
 * Forces validation of value and returns valid value.
 * @function
 * @name NumericValidator#Force
 * @param {string} value The value to force validation from.
 * @return {number}
 */
function NumericValidator_Force(value) {
    if (Validator.Numeric.Validate(value)) { return (parseFloat(value)); }
    //  remove excess dots
    value = '' + value;
    if (value.length > 0) {
        var count = value.match(/\./g);
        if ((count != null) && (count.length > 1)) {
            count = value.indexOf('.');
            value = value.substr(0, count + 1) + value.substr(count + 1).replace(/\./g, '');
        }
        //  remove excess hyphens, non-numbers and non-decimals
        if (value.length > 0) {
            if (value.substr(0, 1) == '-') {
                value = '-' + value.replace(/[^\d.]/g, '');
            } else {
                value = value.replace(/[^\d.]/g, '');
            }
        } else {
            return (0);
        }
    } else {
        return (0);
    }
    if (value.match(/\d/g) == null) { return (0); }
    return (parseFloat(value));
}

/**
 * Determines whether or not a value is valid.
 * @function
 * @name NumericValidator#Validate
 * @param {string} value The value to determine the validation state of.
 * @return {boolean}
 */
function NumericValidator_Validate(value) {
    return (!isNaN(parseFloat(value)) && isFinite(value));
}
/**
 * Determines whether or not the formatting of the source should be utilized.
 * @name NumericValidator#AllowFormatting
 * @type {boolean}
 * @default {false}
 */
/**
 * Determines whether or not the validator works on multiple lines.
 * @name NumericValidator#Multiline
 * @type {boolean}
 * @default {false}
 */
// noinspection JSClosureCompilerSyntax,JSValidateTypes
NumericValidator.prototype = new Validator(false, false);
NumericValidator.prototype.constructor = NumericValidator;
NumericValidator.prototype.Force = NumericValidator_Force;
NumericValidator.prototype.Validate = NumericValidator_Validate;

/**
 * The global NumericValidator instance.
 * @name Validator.Numeric
 * @type {NumericValidator}
 * @static
 */
Validator.Numeric = new NumericValidator();