Dear Ms.Hemlata,
Employment is a legal contract between the employer and the employee subject to the provisions of various laws and equitable practice of valid conventions applicable to the said contract.
I would request you to go through today's Indian Express e-paper which highlights the judgment of the Punjab and Haryana High Court about the women's right in their employment in the uniformed services.
Imposing such a restrictive covenant like the one you mentioned, in the words of the hon'ble High Court, tantamounts to " forcing a choice between bearing a child and taking up employment interferes both with a woman's reproductive rights as well as her right to employment and that such an action has no place in modern India ".
Therefore both the actions of the employer you mentioned are illegal.