We consider the optimal portfolio and consumption problem for a jump-diffusion process with regime switching. Under the criterion of maximizing the expected discounted total utility of consumption, two methods, namely, the dynamic programming principle and the stochastic maximum principle, are used to obtain the optimal result for the general objective function, which is the solution to a system of partial differential equations. Furthermore, we investigate the power utility as a specific example and analyse the existence and uniqueness of the optimal solution. Under the constraints of no-short-selling and nonnegative consumption, closed-form expressions for the optimal strategy and the value function are derived. Besides, some comparisons between the optimal results for the jump-diffusion model and the pure diffusion model are carried out. Finally, we discuss our optimal results in some special cases.