/** * @requirefiles {controls/Validator/Validator.js} */ /** * The IntegerValidator class provides for validation of numeric integer values. * @class IntegerValidator * @extends Validator */ function IntegerValidator() { } /** * Forces validation of value and returns valid value. * @function * @name IntegerValidator#Force * @param {string} value The value to force validation from. * @return {number} */ function IntegerValidator_Force(value) { if (Validator.NumericInteger.Validate(value)) { return (parseInt(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); } if (Validator.NumericInteger.Validate(value)) { return (parseInt(value)); } return (parseInt(Math.round(value))); } /** * Determines whether or not a value is valid. * @function * @name IntegerValidator#Validate * @param {string} value The value to determine the validation state of. * @return {boolean} */ function IntegerValidator_Validate(value) { return (Validator.Numeric.Validate(value) && (parseInt(value) == parseFloat(value)) && (('' + value).match(/\./g) == null)); } /** * Determines whether or not the formatting of the source should be utilized. * @name IntegerValidator#AllowFormatting * @type {boolean} * @default {false} */ /** * Determines whether or not the validator works on multiple lines. * @name IntegerValidator#Multiline * @type {boolean} * @default {false} */ // noinspection JSClosureCompilerSyntax,JSValidateTypes IntegerValidator.prototype = new Validator(false, false); IntegerValidator.prototype.constructor = IntegerValidator; IntegerValidator.prototype.Force = IntegerValidator_Force; IntegerValidator.prototype.Validate = IntegerValidator_Validate; /** * The global IntegerValidator instance. * @name Validator.NumericInteger * @type {IntegerValidator} * @static */ Validator.NumericInteger = new IntegerValidator();