```ts
function codeValid(code: string, length: number): boolean {
  if (length <= 0) {
    throw new Error('Length must be greater than zero');
  }

  const regex = /^[A-Z0-9]+$/;
  return regex.test(code);
}
```