I can't speak for all countries, but in the United States, it is indeed illegal to impersonate a soldier. It is also illegal for a soldier to wear their uniform when not performing official military duties or traveling to and from said duties. In that vein, walking down the street in uniform for the express purchase of catching the eye of a lady would not be permissible.