First of all make sure you typed it correctly. Some letters and numbers are very similar and can be confused like 0 and O, I and 1, 8 and B.
Was it bought online on Origin or was it bought in a store in a box. If the latter was the box sealed? If it was not sealed return it for a refund.
I'm trying to register my game but it says the serial code is invalid/already used
Depending on the situation the solution to this may vary.
You bought the game on Origin
If you bought the game on Origin, it's not necessary to register the code anywhere. Download the Origin Client here: http://origin.com/download, log in with the same email you bought the game with and find the game in the Game Library tab within the Origin Client to download. You don't need the serial code.
You bought the game on DVD and the box was sealed
Make sure you typed the code right. The following letters look very similar and are easily mistaken for each other
If it still says it's invalid, try taking it back to the store you bought it from and exchange it. If they are not willing to do that, contact an EA Game Advisor with proof of purchase ready.
You bought the game on DVD and the box was not sealed/it's a used game
Used games cannot be re-registered. Take it back to where you bought it and get a refund.
You bought a key from a key seller
Contact the key seller for a replacement. If you bought the game from an unauthorized seller, it's possible that EA blocked the key if they were bought fraudulently by the seller. You're better off to only buy from authorized sellers.
You have already registered the game yourself and are trying to reinstall the game
The game does not need to be registered again. Login in the Origin Client with the Email/PW you first registered the game on and download and install the game from there. The game only needs to be registered once and you won't need the code again after your initial registration. This is true for both the DVD and the download version. You can skip the activation step on reinstalling.