Providing feedback when the user leaves the field is probably the best default behavior because validation occurs after the entry is made explicit. The primary principle of good form validation is this: Talk to the user! Inline validation is a method to check the validity of input and give feedback before submission. In theory, it motivates the customers by confirming they are on the right track when they type correctly, providing satisfaction. But it is also a subject of debate because error messages tends to be ignored.
Data required has to be given in a particular format (zip codes, phone numbers, CC numbers, email address etc..) or with a limit of caractere.
Use color and icon(s) to differentiate success and errors and provide help text (for error).
Data is checked by the system.
Use color and icon to inform about validity/no validity of data and provide help text (for error).
Use color and icon and provide help text in case of no matching.
Don't validate if:
Use tooltip to inform about password policy and check instantly.
Character or word count
Use help text to count characters and check instantly.