/** * @requirefiles {controls/Validator/Validator.js} */ /** * The UnsignedNumericValidator class provides for validation of unsigned numeric values. * @class UnsignedNumericValidator * @extends Validator */ function UnsignedNumericValidator() { } /** * Forces validation of value and returns valid value. * @function * @name UnsignedNumericValidator#Force * @param {string} value The value to force validation from. * @return {number} */ function UnsignedNumericValidator_Force(value) { if (Validator.UnsignedNumeric.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 hyphens, non-numbers and non-decimals if (value.length > 0) { 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 UnsignedNumericValidator#Validate * @param {string} value The value to determine the validation state of. * @return {boolean} */ function UnsignedNumericValidator_Validate(value) { return (!isNaN(parseFloat(value)) && isFinite(value) && (parseFloat(value) == Math.abs(parseFloat(value)))); } /** * Determines whether or not the formatting of the source should be utilized. * @name UnsignedNumericValidator#AllowFormatting * @type {boolean} * @default {false} */ /** * Determines whether or not the validator works on multiple lines. * @name UnsignedNumericValidator#Multiline * @type {boolean} * @default {false} */ // noinspection JSClosureCompilerSyntax,JSValidateTypes UnsignedNumericValidator.prototype = new Validator(false, false); UnsignedNumericValidator.prototype.constructor = UnsignedNumericValidator; UnsignedNumericValidator.prototype.Force = UnsignedNumericValidator_Force; UnsignedNumericValidator.prototype.Validate = UnsignedNumericValidator_Validate; /** * The global UnsignedNumericValidator instance. * @name Validator.UnsignedNumeric * @type {UnsignedNumericValidator} * @static */ Validator.UnsignedNumeric = new UnsignedNumericValidator();