```ts
export function codeValid(code: string, length: number): boolean {
  if (length <= 0) {
    throw new Error('Length must be greater than zero');
  }
  
  for (let i = 0; i < length; i++) {
    const char = code[i];
    if (!char.match(/[A-Z0-9]/)) {
      return false;
    }
  }
  
  return true;
}
```