Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

TWIN FALLS, Idaho — An Idaho judge has ordered a 19-year-old man not to have sex with anyone before he marries as part of his sentencing for statutory rape of a 14-year-old girl.

Judge Randy Stoker sentenced Cody Duane Scott Herrera of Twin Falls to five to 15 years in prison, but he suspended the sentence for a one-year rider program.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

If the unmarried Herrera completes that program, he'll be released on probation, which requires celibacy unless he weds.

Stoker said the probation condition is needed because Herrera told pre-sentence investigators he's had 34 sexual partners.

"If you're ever on probation with this court, a condition of that will be you will not have sexual relations with anyone except who you're married to, if you're married," Stoker told Herrera.

Cody Duane Scott Herrera. Twin Falls County Jail / via KXAN

Herrera in March pleaded guilty to statutory rape of the 14-year-old girl. "It was his intent from the beginning to take what he wanted from my 14-year-old child — her virginity," the victim's mother told the court.

Shaakirrah R. Sanders, an associate professor at the University of Idaho College of Law, said the probation condition might be illegal or unenforceable.

"I would suspect (a judge can't do that)," Sanders said. "I think it infringes on his constitutional rights."

Sanders said judges have discretion in creating special probation terms, but they can't violate the federal or state constitution. "I think if he appealed, he would win," Sanders said.