A controversial law that will make it harder for foreign tourists to buy cannabis at the Netherlands' famous coffee shops has been upheld by a Dutch court.

The law, which reverses 40 years of liberal drugs policy in the Netherlands, is targeted at the many foreigners who have come to see the country as a soft drugs paradise and to tackle a rise in crime related to the drug trade.

The law, which goes into force in three southern provinces on May 1st before going nationwide next year, means coffee shops can only sell cannabis to registered members.

Only locals, whether Dutch or foreign residents, will be allowed to join a coffee shop, and each coffee shop will be limited to 2,000 members.

Some users regard the requirement to register as an invasion of privacy.

Fourteen coffee shop owners and several pressure groups challenged the law in the courts, saying they should not be asked to discriminate between locals and non-locals.

A lawyer for the coffee shop owners said they would appeal.

The Dutch government, which collapsed at the weekend, had also planned to forbid any coffee shops within 350 metres of a school, with effect from 2014.

The government in October launched a plan to ban what it considered to be highly potent forms of cannabis - known as "skunk" - placing them in the same category as heroin and cocaine.