This sloka is useful to prevent having nightmares. Every night before sleeping, sit and chant this sloka 3 times in your mind. It is the name of 7 powerful gods and characters in Hindu mythology. it is believed that the utterance of their name is enough to keep all evil entities away from causing nightmares
Om braahmanam shankarum vishnum
yamum ramum dhanum bhaliim
sapthai thaan yah smare nithyam
dhuswapnam thasyanuu nashyathi
The sloka given below is also used to prevent having nightmares. This sloka is especially beneficial for little kids to chant before sleeping. It is advisable to try and instill this practice of sloka chanting as a habit in children at a young age itself. This sloka is is the 12 divine names of lord Hanuman , who is always willing to come to the rescue of his devotees.
om hare rama
hanuman anjanasuno vayuputro mahabhala
Rameshtt phalguna sakha pingaksh amithavikrama
udhadhikramana sithashokavinashaka
lakshmana praanadatha dasagreevasyadarpaha