def varchar(length):
    """
    Factory for a character length validator of the specified length.
    """
    length = int(length)

    def char_length_validator(string):
        """
        Validate a string ensuring that it doesn't exceed a maximum length.
        """
        if string is None:
            return

        string = str(string)
        if len(string) > length:
            raise ValueError("Value '%s' exceeds character limit "
                             "of %i." % (string, length))
        return string

    return char_length_validator