For the Einstein-Maxwell equation system, with perfect fluid in a static and spherically symmetrical spacetime, we report an analytical internal solution which is obtained by imposing the Karmarkar condition, the behaviour of the solution is such that the density and pressures are monotonically decreasing functions while the electric field function is a monotonically increasing function that is adequate to represent compact objects. In particular we have these characteristics for the observational values of mass (1.29 ± 0.05) M⊙ and radius (8.831 ± 0.09) km of the star SMC X-4. We will analyze the two extremes the one of minimum compactness umin = 0.20523 (M = 1.24 M⊙, R = 8.921 km) and the one of maximum compactness umax = 0.22635 (M = 1.34 M⊙, R = 8.741 km), resulting that the electric charge Qumin ∈ [1.5279, 1.8498]1020C and Qumax ∈ [1.6899, 1.9986]1020C respectively, implying that the case with higher compactness has a higher electric charge. Also in a graphic manner, it is shown that the causality condition is satisfied and that the solution is stable against infinitesimal radial adiabatic perturbation and also in regards to the Harrison-Novikov-Zeldovich criteria