Karen, Legal is one consideration. More's point is important - how will a remodel affect resale - non-compliant work may result in problems.

First, the toilet tank must be greater than 15" from the tank center to any wall or cabinet on each side (in the center of a 30"opening)the toilet paper roll is allowed within this area.

Second, the answer to your question. The UPC requirement is 24" and the IRC is 21". My guess is the UPC would be the conrtolling code in your case. A quick call to your local building department should answer precisely. Some toilets are smaller front to back than others and toilets with elongated bowls require more space. The toilet flange location contols the toilet location. The bottom line is check the rough-in requirements of a specific toilet.

After you consider all the above and still have questions, call a good plumber - they may have solutions for your particular situation.