Can I pay several months of rent in Spain to prove I'm solvent?

Newcomers, self-employed workers and digital nomads in Spain can find it very hard to convince landlords to rent to them if they don't have a Spanish job contract. So what does the law say about paying several months of rent to prove you're reliable?