```python
def code_valid(code: str, length: int) -> bool:
    if length <= 0:
        raise ValueError("Length must be greater than zero")
    
    for char in code:
        if not (char.isalpha() or char.isdigit()):
            return False
    
    return True
```