import re


def is_valid_record2(parsed_record):
    """Check if parsed_record is properly formatted"""
    if not (
        "byr" in parsed_record
        and parsed_record["byr"].isdigit()
        and len(parsed_record["byr"]) == 4
        and (1920 <= int(parsed_record["byr"]) <= 2002)
    ):
        return False

    if not (
        "iyr" in parsed_record
        and parsed_record["iyr"].isdigit()
        and len(parsed_record["iyr"]) == 4
        and (2010 <= int(parsed_record["iyr"]) <= 2020)
    ):
        return False

    if not (
        "eyr" in parsed_record
        and parsed_record["eyr"].isdigit()
        and len(parsed_record["eyr"]) == 4
        and (2020 <= int(parsed_record["eyr"]) <= 2030)
    ):
        return False

    if "hgt" in parsed_record:
        match = re.match(r"(?P<value>\d+)(?P<unit>in|cm)$", parsed_record["hgt"])
        if not match:
            return False
        value = int(match.group("value"))
        unit = match.group("unit")
        if not (
            (unit == "cm" and 150 <= value <= 193)
            or (unit == "in" and 59 <= value <= 76)
        ):
            return False
    else:
        return False

    if not (
        "hcl" in parsed_record and re.match(r"#[0-9a-f]{6}$", parsed_record["hcl"])
    ):
        return False

    if not (
        "ecl" in parsed_record
        and re.match(r"amb|blu|brn|gry|grn|hzl|oth$", parsed_record["ecl"])
    ):
        return False

    if not ("pid" in parsed_record and re.match(r"\d{9}$", parsed_record["pid"])):
        return False

    return True