Quantum mechanics of a particle in an infinite square well under the influence of a time-dependent electric field is reconsidered. In some gauge, the Hamiltonian depends linearly on the momentum operator, which is symmetric but not self-adjoint when defined on a finite interval. In spite of this symmetric part, the Hamiltonian operator is shown to be self-adjoint. This follows from a theorem by Kato and Rellich which guarantees the stability of a self-adjoint operator under certain symmetric perturbations. The result, which has been assumed tacitly by other authors, is important in order to establish the equivalence of different Hamiltonian operators related to each other by quantum gauge transformations.