Sen. Ted Cruz (R-Texas) said Wednesday on "Fox News @ Night" that President Trump is right about the need to restrict birthright citizenship.

In an interview earlier this week, Trump said he wants to use an executive order that would deny birthright citizenship to the children of illegal immigrants. Legal scholars have disputed whether that can be done, arguing a new law by Congress or a constitutional amendment would be needed to change the interpretation of the 14th Amendment.

Cruz said granting birthright citizenship "doesn't make any sense" and most countries do not allow it.

FL Student, Mom Shocked by Test Question About 'Angry Right Wing' in America

WATCH: Young Beto O'Rourke Supporters Struggle to Name Anything He's Accomplished

"What it ends up doing is incentivizing illegal immigration. We need to be securing the border and stopping illegal immigration. I agree with the president, I've long agreed with ending birthright citizenship as a policy matter," said Cruz, adding that the courts will have to resolve how to change the policy.

"We should not be encouraging illegal immigration," he added.

Cruz is facing a tough re-election battle against Democrat U.S. Rep. Beto O'Rourke, whom he accused of supporting "open borders, amnesty and socialism." A recent Quinnipiac University poll showed O'Rourke leading Cruz 60 percent to 36 percent among Hispanic likely voters.

But Cruz disputed that Hispanics in the border state are onboard with O'Rourke's liberal stance on immigration.

"Texas Hispanics don't want open borders. If you look at Beto O'Rourke's record on immigration, it is terrible," Cruz argued, saying O'Rourke wants to tear down existing border walls, supports sanctuary cities and opposes Kate's Law.

O'Rourke said he "absolutely" opposes Trump and Cruz on the 14th Amendment.

"Not only must we protect the Fourteenth Amendment and our core national values that we are a country comprised of immigrants and asylum seekers the world over, but we must also protect the 200,000 Dreamers contributing to our communities across Texas from the fear of deportation," he told the Texas Tribune.

ABC News Reporter to Beto O'Rourke: 'You're a Rock Star!'

'We're About 150 Years Late': Turley Says 'There's a Good Debate' Over Birthright Citizenship

McCarthy on Birthright Citizenship: Trump 'Right on Substance' But Executive Order Won't Work