The equivalence of open-set definition of continuous mappings to the $\epsilon-\delta$ definition A function $f: M\rightarrow N$ is defined to be continuous iff $\forall$ open set $U\subseteq N$, the preimage of $U$ is also open.
I was trying to prove that such a definition would be equivalent to the $\epsilon -\delta$ definition in a metric space, and I could only do so if I assume $f$ is surjective, or otherwise a counterexample would be $g: \mathbb{R}\rightarrow\mathbb{R}$ where $g(x)=x^2$. As if I take $U=(-1,1)$, then its preimage is $[0,1)$, which is neither open or closed. In fact, any $U$ containing elements that cannot be achieved by $g$ would face the same problem.
So I was wondering that have I remembered the definition of preimage wrong, or do I need to make sure that $U$ must be chosen from the image set of $f$?

Not so: given $g\colon x \mapsto x^2\colon \mathbb{R} \to \mathbb{R}$,
the preimage (aka inverse image) of $(-1, 1)$ under g is $g^{-1}[(-1, 1)]$ is $(-1, 1)$. Each $y > 0$ is the image under $g$ of two points: $g^{-1}[\{y\}] = \{- \sqrt y, \sqrt y \}$.
For $\varepsilon > 0$, the preimage of $(-\varepsilon, \varepsilon)$ is $(-\sqrt \varepsilon, \sqrt \varepsilon)$. In the case of $x = 0$, an obvious choice of $\delta$ presents itself...
Re:

In fact, any [open] $U$ containing elements that [are not in the range of] $g$ would face [some] problem.

There's no problem, $g$ doesn't have to be surjective. The preimage of $U$ equals the preimage of $U \cap image(g)$.
