A.C.
When my son was young and did the same thing I would take his hand and let him pat my hair [sounds funny but that is the best way to describe it] and say pretty pretty, nice. Even when he went for my earring I did the same thing he eventually stopped pulling but if he wanted to touch he would say pretty, pretty, nice. When he was a toddler and we would be out shopping and he saw something I would say pretty, pretty, no touch, look pretty, no touch and that worked for me good luck