public static function validateStudentId($studentId) { if (!preg_match("/^[0-9]{6,7}\$/", $studentId)) { throw new Exception("Student id can contain only numbers of length 6 to 7"); } if (StudentFetcher::existsStudentId($studentId)) { throw new Exception("Student id entered already exists in database."); // the array of errors messages } }