Restricting the field on condition

I am trying to create a custom field which should become mandatory only on a particular condition.

Like, I want to put a production order reference in the material request field but system should make it mandatory only when the purpose of material request is production order.

You can do it using a Custom Script.