Here's the short answer: No. You should not wear glasses or contact lenses on the beach.
The sand and the ocean part of the beach comes with their own set of problems. They both have their pros and cons but generally you should avoid wearing glasses/contacts in either.
Generally speaking, there isn't much issue with wearing glasses on sand. But if the beach you're at has particularly rough or rocky sand, you have to be careful not to scratch your lenses.
Wearing contact lenses on the sand however is a terrible idea. A gust of wind could blow sand in your eye and cause discomfort. Contact users know the painful sting and irritation of grit/dirt stuck behind their lenses.
Now if you're planning on going swimming in the ocean, stay away from wearing either.
Regular prescription glasses are not made for water, especially salt water. Your glasses have coatings to improve the quality of vision (anti-reflective), in salt water, these coatings will be ruined.
Glasses won't stay on while you are swimming. You could very easily lose your expensive prescription glasses forever.
As obvious as it is, you should not wear contact lenses in the ocean. The FDA advises people not to wear contacts while entering any body of water. Water contains various bacterias which may infect your eyes if they get in your contact.
Water and salt dry out contacts, making them extremely uncomfortable. So surely enough, salt water will blur your vision if you are wearing contacts.
Instead, you should wear prescription swimming goggles and prescription sunglasses.
Both of these pieces provide UV protection, clear vision, and will keep you safe from sand or salt. They can be customized for myopia, hyperopia, prism, and astigmatism.
Prescription swimming goggles are snug and great for the ocean, you can swim without worries. Prescription sunglasses give you enough coverage for the sand, or ocean if you don't get your face wet.
Prescirption sunglasses are especially great if you have a hard time seeing without glasses.