public static function validateCode($majorCode) { $majorCode = trim($majorCode); if (!preg_match("/^[A-Z0-9]{1,10}\$/", $majorCode)) { throw new Exception("Major code can only contain capital letters in the range of A-Z, 0-9 and of length 1-10."); } if (MajorFetcher::codeExists($majorCode)) { throw new Exception("Major code already exists on database. Please insert a different one."); } return $majorCode; }