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