Is it sufficient to check only open intervals in order to prove that a real function is measurable? Let $f : \mathbb R \to \mathbb R$. We say that $f$ is measurable if, for every $S \in \mathcal B$ where $\mathcal B$ is the Borel algebra on $\mathbb R$, we have that $f^{-1}[S] \in \mathcal B$. 
I would like to know if the following holds:
$$f \text{ is measurable } \iff f^{-1}[(a,b)] \in \mathcal B \text{ for all } a,b \in \mathbb R.$$
The "$\Longrightarrow$" implication obviously holds, but I was wondering if the other one holds as well. This might be true thanks to the fact that $\mathcal B$ is the $\sigma$-algebra generated by open sets (in the euclidean topology of $\mathbb R$), and the set of all open intervals is a base for the euclidean topology, so the open intervals generate the whole $\mathcal B$, and maybe it is always sufficient to check the measurability property for any $\sigma$-algebra just on a base of it.
The aim of this question is to find a quick, but still rigorous, way to prove that (e.g.) the function defined by
$$f(x)=
\begin{cases}
x &\text{ if } x \leq 0 \\
x+1 &\text{ if } x > 0
\end{cases}$$
is measurable.
Thanks

The answer is YES.
If $f: X\to Y$, and $\mathfrak M$ is a $\sigma$-algebra of subsets of $X$, then
$$
\mathfrak N=\{A\subset Y: f^{-1}[A]\in\mathfrak M\},
$$
is a $\sigma$-algebra of subsets of $Y$. 
Hence, if $f:\mathbb R\to\mathbb R$ has the property that $f^{-1}$ takes open sets to Borel sets, then, $f^{-1}$ takes to Borel sets the minimum $\sigma$-algebra produced by the open sets which is the $\sigma$-algebra of Borel sets.    
