Just tell them to press # when they're done so they dont wait for a digit timeout.
I suppose if your 5 digit ticket numbers were in the 4xxxx and your 7 digit ticket numbers always had as leading 2 digits either month or day and would always be 1-12 or 1-31, you could be crafty in your vectors like collect 5 digit for A. If A >12999 you know its a 5 digit ticket, else, collect 2 digit for B, CATR A+B = C = 7 digit ticket#
Or, just tell them to press #!