If electromagnetic field is long range then why friction works only for contacting surfaces?

It is because matter is made up of approximately equal numbers of positive and negative charges so the long range effect of these charges is negligible ie the bodies concerned are electrically neutral and do not interact with one another.

Friction is to do with electrostatic forces between particle which are nanometres apart and have formed bonds with one another.
For bodies to interact to any significant degree the electron shells on the surface of each body must "touch" ie friction is a contact force.

As you know, atoms are made of positively charged nuclei, surrounded by an equal number of negatively charged electrons. Say the charge of a particular atom is $Z$. There is a distance between the positive and negative charges - the "radius" of the atom - and so we know that perhaps $Z/2$ electrons are "closer" to the contact surface than the positive charge of the nucleus. We can grossly model this as half of the electrons are "away" from the contact surface, and half are "toward" the contact surface, for both surfaces. Further simplifying to model each half as a point charge, and the nucleus itself as a point charge.

Modeling surfaces as dipoles

The electrostatic force between the two surfaces can be derived easily. Since the force is inversely proportional to square distance, the $1/D^{2}$ repulsive term dominates when the surfaces are close together. When the surfaces are far apart compared to $d$, the two electric dipoles representing each atom cancel.

Of course, this extremely simplistic line of argument can be extended to include surface charges instead of point charges, and to improve some approximation with respect to charge distribution, but the gist is there.

This is not, of course, meant to suggest that friction happens due to some shear force between perfectly parallel planar charges. This was to address the question of how the long range electromagnetic field can cause friction to happen only over short distances.