The charge confinement in InAs/InP based quantum wells and self-assembled quantum wires is investigated theoretically and experimentally through the study of the exciton diamagnetic shift. The numerical calculations are performed within the single-band effective mass approximation, including band nonparabolicity and strain effects. The exciton diamagnetic shift is obtained for quantum wires and quantum wells incorporating local width fluctuations, as well as the electron-hole Coulomb interaction energy. Both electrons and holes (but to a lesser extent) show a substantial penetration into the InP barrier. A detailed comparison is made between the theoretical and experimental data on the magnetic field dependence of the exciton diamagnetic shift. Our theoretical analysis shows that excitons in the InAs/InP quantum well are trapped by local well width fluctuations.