According to coulomb's law there is an force between two charges directly proportional to the product of their masses and inversely proportional to the square of the distance between them ...
So when you walk on a carpet bcz of friction electrons remove from you hair and that's how an electric charge is established between you and carpet ..So there comes a coulomb force ..That's why your hair stand's on the edge when it is really dry outside.