RICHMOND — The Virginia Senate approved a bill Monday to allow religious and political student organizations at public universities to turn away would-be members who do not share the group’s mission.

Supporters of the bill, including the Family Foundation of Virginia, said the measure protects the right of free association by giving clubs the authority not to take “all comers.”

Approved 22 to 18, the legislation would prevent public universities from using campus anti-discrimination policies against any club that “limits its core functions to persons committed to its mission.”

Opponents said the measure was intended to allow student groups to discriminate against gay students.

The bill’s patron, Sen. Mark Obenshain (R-Harrisonburg), a candidate for attorney general, said the legislation was “viewpoint neutral.”

Without it, he said, “A vegan group couldn’t require that its members be vegans,” he said. . . .“It will protect the vegans, it will protect Republicans, it will protect Democrats. Its’ an equal-opportunity bill.”

Sen. Janet D. Howell (D-Fairfax) said on the floor that Obenshain proposed a bill a few years ago against allowing gay and lesbian clubs at public schools.

However, Obenshain later said he did not propose, co-sponsor or vote on the legislation Howell mentioned.

(Editor’s note: This story has been updated to clarify that Sen. Mark Obenshain said he had no role in legislation Sen. Janet D. Howell mentioned on the floor of the state Senate on Tuesday.)