When I was in Airforce , there were few with longer hair who hid it with their hats and a few even wore short wigs to hide it.
Getting away with it depended on your job, how observant and strict your commanding officer was, how you hid it, and just plain luck.
Long straight hair was easier to hide than long curly hair too. My hair was curly, I wasnt going to wear a wig, so I just waited till I was told to get a haircut.