In physics, we often expand functions $f(x)$ of a real variable $x$ which is piecewise continuous in the interval $(-1,1)$ along with its derivatives, in terms of Legendre polynomials $\{P_n(x)\}$ as $$f(x)=\sum\limits_{n=0}^{\infty}c_nP_n(x)$$ where $c_n$ can be obtained using $$c_n=\frac{2n+1}{2}\int\limits_{-1}^{+1}f(x)P_n(x)dx.$$
Is it always possible to do such an expansion for any $f(x)$? I'm looking for the necessary and sufficient conditions.