boolean checkValidCode(String code, int maxDigit){
    try {
      for (char c : code.toCharArray()){
        check(c >= '0');
        check(c <= '0'+maxDigit);
      };
    } catch (Exception e) {
      return false;
    }
    return true;
  }