Five transgender members of the US military, including Iraq and Afghanistan war veterans, sued President Donald Trump on Wednesday, challenging his ban on transgender people serving in the armed forces.

Trump said on Twitter on July 26 that the US government "will not accept or allow transgender individuals to serve in any capacity" in the military, a reversal of Pentagon policy that the lawsuit said was made without consulting senior military commanders.

The surprise announcement, citing healthcare costs and unit disruption, appealed to some in Trump's conservative political base. But it also created uncertainty for thousands of transgender service members who came out after the Pentagon said in 2016 that transgender people would be allowed to serve openly.

"Trump’s directive to exclude transgender people from military service has created a tidal wave of harms that have already been felt throughout our armed services. Transgender service members have been blindsided by this shift and are scrambling to deal with what it means for their futures and their families," Shannon Minter, a transgender legal expert and legal director at the National Center for Lesbian Rights, said in a press release. "The President’s mistreatment of these dedicated troops will serve only to weaken and demoralize our armed forces."

Trump's tweets appeared to dismiss findings from a RAND Corporation study commissioned by the Pentagon, which found that allowing transgender people to serve would "cost little and have no significant impact on unit readiness."

The White House did not immediately respond to the lawsuit, which was filed in US District Court in Washington, D.C.

The service members suing the president are three US Army soldiers, one US Air Force airman and one member of the US Coast Guard who are on active duty.

All have come out as transgender to their commanding officers but are anonymous in the lawsuit, named only as Jane Doe, for fear of retribution, said Jennifer Levi, a lawyer from GLBTQ Legal Advocates & Defenders. The group filed the lawsuit along with the National Center for Lesbian Rights.

The American Civil Liberties Union said it was preparing its own lawsuit as well.

The lawsuit said Trump's tweets violate the rights of the service members to due process and equal protection under the law. It asks the court to declare Trump's directive unconstitutional and to issue injunctions to stop it.

The defendants are listed as Trump, Defense Secretary James Mattis, and other military leaders including Joseph Dunford, the chairman of the Joint Chiefs of Staff. Dunford said in a memo a day after Trump's tweets that there would be no change in policy until Mattis received an official order from the president.

That order has yet to be issued.

"In the meantime, we will continue to treat all of our personnel with respect," Dunford said.

Levi said the plaintiffs, some of whom are near retirement, need not wait for an official policy because the tweets alone created uncertainty about their futures.

(Additional reporting by Daniel Trotta; editing by Grant McCool)