MiddleAge under the DofE's guidance to schools regarding uniforms it does seem that schools can enforce any rule they like, as long as they aren't being discriminatory on religious grounds. They can discipline pupils for not adhering to the rules and even exclude pupils for it if the situation isn't resolved. 
"Teachers can discipline pupils for breaching the school’s rules on appearance or uniform. This should be carried out in accordance with the school’s published behaviour policy.
A head teacher, or a person authorised by the head teacher, may ask a pupil to go home briefly to remedy a breach of the school’s rules on appearance or uniform. When making this decision schools need to consider the child’s age and vulnerability, the ease and time it will take, and the availability of the child’s parents. This is not an exclusion but an authorised absence. However, if the pupil continues to breach uniform rules in such a way as to be sent home to avoid school, or takes longer than is strictly necessary to effect the change, the pupil’s absence may be counted as an unauthorised absence. In either case the pupil’s parents must be notified and the absence should be recorded. If a school is considering excluding a pupil in response to breaches of uniform policy then this must be in line with the legal requirements for exclusion."
If you really wanted to fight it though, you could go the route of gender inequality, which is also dealt with in the guidelines. There can't justifiably be a rule about boys only being allowed hair of x length, when girls are allowed to have it whatever length they like, as long as it's tied back, if you are looking at things from a gender equality point of view.
^"A school should also bear in mind the concept of “indirect” discrimination. This involves the application of a requirement, which, although applied equally to everyone, puts certain people at a particular disadvantage because of their gender, race, sexual orientation, religion or belief or gender reassignment. Such a requirement will need to be justified as a proportionate way of achieving a reasonable objective if it is to be lawful, and the policy will need to be flexible enough to allow for necessary exceptions."
My feeling is that that could still fall down on the last part 'allow for necessary exceptions' as it would be very hard to explain how long hair should be seen as 'necessary'.