def alphanum(columns, name=None, extended=False, isLast=False):
    """
    Creates the grammar for an Alphanumeric (A) field, accepting only the
    specified number of characters.

    By default Alphanumeric fields accept only ASCII characters, excluding
    lowercases. If the extended flag is set to True, then non-ASCII characters
    are allowed, but the no ASCII lowercase constraint is kept.

    This can be a compulsory field, in which case the empty string is
    disallowed.

    The text will be stripped of heading and trailing whitespaces.

    :param columns: number of columns for this field
    :param name: name for the field
    :param extended: indicates if this is the exceptional case where non-ASCII
    are allowed
    :return: grammar for this Alphanumeric field
    """

    if name is None:
        name = 'Alphanumeric Field'

    if columns < 0:
        # Can't be empty or have negative size
        raise BaseException()

    if isLast:
        columns = str('1,' + str(columns))

    # Checks if non-ASCII characters are allowed
    if not extended:
        # The regular expression just forbids lowercase characters
        field = pp.Regex('([\x00-\x60]|[\x7B-\x7F]){' + str(columns) + '}')
    else:
        # The regular expression forbids lowercase characters but allows
        # non-ASCII characters
        field = pp.Regex('([\x00-\x09]|[\x0E-\x60]|[\x7B-\x7F]|[^\x00-\x7F]){' +
                         str(columns) + '}')

    # Parse action
    field.setParseAction(lambda s: s[0].strip())

    # Compulsory field validation action
    if columns:
        field.addParseAction(lambda s: _check_not_empty(s[0]))

    # White spaces are not removed
    field.leaveWhitespace()

    # Name
    field.setName(name)

    return field
Creates the grammar for an Alphanumeric (A) field, accepting only the
    specified number of characters.

    By default Alphanumeric fields accept only ASCII characters, excluding
    lowercases. If the extended flag is set to True, then non-ASCII characters
    are allowed, but the no ASCII lowercase constraint is kept.

    This can be a compulsory field, in which case the empty string is
    disallowed.

    The text will be stripped of heading and trailing whitespaces.

    :param columns: number of columns for this field
    :param name: name for the field
    :param extended: indicates if this is the exceptional case where non-ASCII
    are allowed
    :return: grammar for this Alphanumeric field