While I agree with Adam Silver's comments in principle, there are ways to optimize live validations for some(!) situations that work just fine.
For example, when unlocking your phone with a numeric passcode, chances are that the device will validate the code as soon as you've entered the final digit.
For more traditional form validation, displaying a checklist with the field's requirements, which is updated in real-time, provides a very user-friendly approach:
(Please do make sure, though, that the differences between the checked vs. not-checked appearances are easier to see than what Apple does here! sigh)
In your particular case, your question implies that the length of the code always is the same, so you have a well-defined trigger for the validation.
A design that I'd play around with, is displaying a gray — think, "neutral" — icon next to the input field, maybe just a gray circle. Once the user has entered the entire code, replace it with a green checkmark or red "x" in a circle (similar to Apple's icons above) to indidate whether the code is valid, or not.
To help the user avoid mistakes, give 'em a helping by including hint text:
Your code will look like this: 123-456-789
Also, make sure that you validate in a way that's human-friendly. E.g., if your code contains letters, but only upper-case ones, don't punish your users if they enter lower-case characters, instead.
P.S.: As so often, ;) Nielsen Norman Group has a detailed article on the topic with some great advice: How to Report Errors in Forms: 10 Design Guidelines.