Yes, legitimately. EA has sold The Sims 3 as a digital download for years, so you can buy it through Origin or the EA app and install it without ever touching a disc.
If you already own a physical copy, the serial code that came in the case can usually be registered to an EA account, which then lets you download it.
What I would steer you away from are the cracked copies floating around download forums. They carry a real risk of malware and they will not receive patches or updates.