The code is effectively just a long random string. When you create a redeemable code, a random string is selected, entered into the database at the exchange and associated with a currency and an amount. That string is your redeemable code. The string is long enough to make it very unlikely that anyone would be able to guess it in a reasonable length of time.
The first person to attempt to redeem the code gets the amount credited to their account on the exchange, which causes the database entry on the exchange for that code to be marked as having been redeemed.
The way to tell whether a code is valid is to try redeeming it. If it works, you're the first to try it. If not, you're either not the first to try using it, or it was never a valid code to start with.
The exchange should prevent "double-spending" by making sure that the "look up whether code is spent; credit account; make code as spent" sequence is an atomic operation. We don't want two users both running through that same sequence at the same time, where both pass the "look up whether code is spent" check, then both accounts get credited, etc.
Mt. Gox has announced that it will stop issuing MTG USD and MTG CAD redeemable codes beginning April 10, 2013: http://www.bitcoinmoney.com/post/44860726799
– Stephen Gornick – 2013-03-11T09:32:15.0571I'm not sure why you're specifically concerned about how you know the code is "still valid". Aren't you equally worried that it was never valid? – David Schwartz – 2012-03-13T04:42:11.067
@David Schwartz: That would be a subset of my worries, yes. But I would not care particularly about the distinction if it was already spent, or not valid at all. – Thilo – 2012-03-13T05:05:01.223