Image copyright AFP Image caption Protesters rallied outside a US army career centre in New York in June

US President Donald Trump has signed a memo reinstating a ban on transgender people serving in the military, which was lifted under Barack Obama.

The memo also halts the use of government funds for sex-reassignment surgery for active personnel.

But Mr Trump left Defence Secretary Jim Mattis to decide whether to retain existing transgender recruits.

The ban, justified on grounds of cost and disruption, faces a legal challenge by transgender rights activists.

"This policy is a shameful slap in the face to people who put their lives on the line everyday to defend our country..." said Jennifer Levi, an official at Glad (GLBTQ Legal Advocates & Defenders), in a statement.

"We are moving quickly with our plaintiffs to see that a court puts a stop to this latest demonstration of President Trump playing politics with people's lives."

Between 4,000 and 10,000 US active-duty and reserve service members are believed to be transgender.

Transgender troops react to ban

Why does the US military buy so much Viagra?

The secret life of a transgender airman

After the Obama administration announced last year that they would be allowed to serve openly in the military, many active duty members came out.

Favour to US military?

The memo was widely anticipated following tweets Mr Trump made about the issue last month.

Mr Trump directed the military to "return to the longstanding policy and practice on military service by transgender individuals prior to June 2016".

He suggested that his predecessor in the White House had not thought through whether the policy would "hinder military effectiveness and lethality, [or] disrupt unit cohesion".

Media playback is unsupported on your device Media caption Riley Dosh explains why she wants to defend her country

He said he had done the Pentagon a "great favor" by banning transgender troops, saying the issue had been "complicated" and "confusing" for the military.

The Obama-era policy had included a provision for the military to provide medical help for service members wanting to change gender.

In his memo, Mr Trump directed the Department of Defense and Department of Homeland Security to stop using government funds for sex-reassignment procedures unless it was necessary to "protect the health of an individual who has already begun a course of treatment to reassign his or her sex".