In a paper I am writing I need to show that a real-valued function $f\in L^2(B_1)$ belongs to the Sobolev space $W^{1,2}(B_1)$. So far I have been able to show that $Df \mathbb{1}_{f\neq 0}\in L^2(B_1)$, so now I only have to deal with the set $\{f=0\}$. I suspect that it shouldn't matter and that the weak differential $Df$ exists on all $B_1$ and is equal to $Df \mathbb{1}_{f\neq 0}$ a.e., but I am having troubles proving it formally. Any help/hint is appreciated.