A Dutch judge has upheld a controversial law that bans tourists from buying cannabis at the Netherlands' famous coffee shops.

The ban on tourists visiting so-called cannabis cafes will be implemented nationwide by the end of this year.

It targets 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.

Coffee shops can only sell cannabis to registered members. Only locals 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.

The mayor of Amsterdam opposes the plan.

Fourteen cafe owners and several pressure groups also challenged the law in The Hague, saying it is discriminatory.

One owner says it will cost him 90 per cent of his turnover. The cafe owners say they will be lodging an appeal.

The ban is part of a tougher approach to drugs by the Netherlands government.

The law, which reverses 40 years of liberal drugs policy in the country, starts next month in three southern provinces and goes nationwide by the end of the year.

The Dutch government, which collapsed at the weekend, also plans 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.

ABC/Reuters