The best way to teach a foal not to bite is to start when he is still a baby. Take care of him with love and attention. Teach him that when he comes to you for attention or cuddling, you'll give him that, but you'll also take away his nosing and nudging when he comes too close. He won't get used to this treatment and will eventually give up.
One way of achieving that is to hold his nose just a little longer than he wants, so that he takes his nose away on his own. Repeat the gesture each time he comes towards you in the same biting manner. Be careful to not hurt him but consistent until he gives up on trying to bite.
You can also try to teach a horse not to bite by using a trick called 'the pinch'. When you want your horse to stop doing something, you should use the pinch. Pinching is a way of stopping a behavior, that doesn't harm the horse. You can pinch your horse in the nose, between his eyes, on his back, under the tail, or at the top of his leg.