Yes, you can. But there are three side effects of sleeping with glasses.
First of all, you will feel uncomfortable with glasses on your eyes when you are sleeping.
Secondly, your eyes may be poked or hurt by the frame when you are sleeping. When you are sleeping, you don't know how you move actually.
Last but not the least, the glasses may leave marks on your face after being pressed to your face for a whole night.
It is not ok for you to sleep with glasses. You will leave the deep nose pad print at the nose part. You should not do this. At the same time, you may break the eyeglasses under you unconscious way during the sleep. You should sleep with no glasses. Please remember this. You should not even wear the contact lenses during your sleep which may have more serious result.
Sleep is time to relax, if you wear glasses to bed, it will put pressure on your mind, so that you do not sleep at ease, right? So I suggest you take it off, you can put it at hand to guarantee it is easy to use when you work at night. You had better not wear both glasses and contact lens when you are sleeping, especially the contact lens, because the former make you feel uncomfortable, while the latter damage your eyes.