I was looking through some problems in one of my books which does not have solutions in the back, and I found a problem stating to construct a proof for the following problem. If someone would not mind verifying whether or not the argument is valid, I would appreciate it.
Problem
Let the set $I = \{1, \dotsc, n\}$ for some $n \in \mathbb{N}$, let $B$ be a set, let $A_1, \dotsc, A_n$ be sets, let $U_i \subseteq A_i$ be a subset for all $i \in I$, and let $f: B \rightarrow A_1 \times \cdots \times A_n$ be a function. Prove that
$$f^{-1}(U_1 \times \cdots \times U_n) = \bigcap_{i \in I} (f_i)^{-1}(U_i)$$
where the $f_i$ are the coordinate functions of $f$ (Recall that the coordinate function $f_i : B \rightarrow A_i$ is defined by $f_i = \pi_i \circ f$ for each $i = \{1, \dotsc, n\}$, and the function $\pi_i: A_1 \times \cdots \times A_n \rightarrow A_i$ is a projection mapping).
Proof
First, let $b \in B$. If $b \in f^{-1}(U_1 \times \cdots \times U_n)$, then there exists an image $f(b) \in U_1 \times \cdots \times U_n$, so that $f(b) = (u_1, \dotsc, u_n)$ for some $u_i \in U_i$, where $i \in I$. Mapping $f(b)$ to an element in $U_i$ by $\pi_i$, we obtain the image $\pi_i(f(b)) = f_i(b) \in U_i$. Consequenlty, $b \in (f_i)^{-1}(U_i)$ for each $i \in I$, so we can write
$$b \in \bigcap_{i\in I} (f_i)^{-1}(U_i)$$
from which we conclude that
$$f^{-1}(U_1 \times \cdots \times U_n) \subseteq \, \bigcap_{i \in I} (f_i)^{-1}(U_i)$$
Now suppose that $b\in B$. Assuming $m \in \bigcap_{i \in I} (f_i)^{-1}(U_i)$, we deduce that, for every $i \in I$, $b\in (f_i)^{-1}(U_i)$. Hence, there exists $f_i(b) \in U_i)$ such that $f_i(b) = \pi_i(f(b))$. Define the preimage $(\pi_i \circ f)^{-1} = \{u \in U_1 \times \dotsc \times U_n \, : \, (\pi_i \circ f)(u) \in U_i\}$. Clearly, $\pi_i(f(b)) \in (\pi_i \circ f)^{-1}$, so $f(b) \in U_1 \times \cdots \times U_n$. Consequently, $b \in f^{-1}(U_1 \times \cdots \times U_n)$. Therefore,
$$\bigcap_{i \in I} (f_i)^{-1}(U_i) \subseteq f^{-1}(U_1 \times \cdots \times U_n)$$
We conclude that
$$f^{-1}(U_1 \times \cdots \times U_n) = \bigcap_{i \in I} (f_i)^{-1}(U_i)$$
$\blacksquare$
Your proof is ok. It can be proved it in a simpler way
Since $$ U_1\times\cdots\times U_n=U_1\times A_2\times\cdots\times A_n\cap A_1\times U_2\times\cdots\times A_n\cap\cdots \cap A_1\times A_2\times\cdots\times U_n $$ \begin{align} f^{-1}(U_1\times\cdots\times U_n)&=f^{-1}(U_1\times A_2\times\cdots\times A_n)\cap f^{-1}(A_1\times U_2\times\cdots\times A_n)\cap\cdots \\&\quad\cap f^{-1}(A_1\times A_2\times\cdots\times U_n) \\ &=f_1^{-1}(U_1)\cap f_2^{-1}(U_2)\cap\cdots\cap f_n^{-1}(U_n) \\ &=\bigcap_{i=1}f_i^{-1}(U_i) \end{align} where $f^{-1}(A_1\times\cdots \times U_i\times\cdots\times A_n)$ maps to $A_i$ only and thus equals $f_i^{-1}(U_i)$.