The New Jersey Supreme Court today upheld a lower court ruling invalidating ordinances in Cherry Hill and Galloway Township that severely restricted where registered sex offenders could live.

The decision could nullify hundreds of similar ordinances passed in townships around New Jersey.

The Supreme Court said the state-wide Megan's Law, a systematic law for dealing with paroled sex offenders, takes precedence over local efforts.

In a summary of its decision, the Supreme Court said Cherry Hill and Galloway's ordinances were "precluded by the present, stark language of Megan's Law."

In 2005, the two townships passed nearly identical laws that banned convicted sex offenders from living within 2,500 feet of schools, parks, churches, or other places where children might congregate.

In Cherry Hill, the ordinance rendered nearly the entire township off-limits to sex offenders.

Two sex offenders in Cherry Hill and one in Galloway - a Richard Stockton College freshman - quickly challenged.

Those challenges became test cases for municipalities across the state that sought to enact similar bans on sex offenders.

Contact staff writer Troy Graham at 856-779-3893 or tgraham@phillynews.com.