def validate(self, value, messages=None, prefix=None):
        """validate(value[, messages[, prefix]]) -> True | False

        Validates the given value according to this PrimitiveType
        definition.  Validation error messages are appended to an optional
        messages array, each with the optional message prefix.
        """
        valid = False

        def log(msg):
            if messages is not None:
                if prefix is not None:
                    tok = msg.split()
                    msg = prefix + ' ' + tok[0].lower() + " " + " ".join(tok[1:])
                messages.append(msg)

        if self.string:
            valid = type(value) is str
        else:
            if type(value) is str:
                log("String '%s' cannot be represented as a number." % value)
            elif type(value) not in (int, long, float):
                log("Value '%s' is not a primitive type." % str(value))
            elif type(value) is float and not self.float:
                log("Float '%g' cannot be represented as an integer." % value)
            else:
                if value < self.min or value > self.max:
                    args = (str(value), self.min, self.max)
                    log("Value '%s' out of range [%d, %d]." % args)
                else:
                    valid = True

        return valid
validate(value[, messages[, prefix]]) -> True | False

        Validates the given value according to this PrimitiveType
        definition.  Validation error messages are appended to an optional
        messages array, each with the optional message prefix.