Here's a
tutorial that does something similar to what you want. It doesn't display an image if the field validates properly, only on failure, but I'm sure you can tweak it. You can find lots more by searching, in fact, I found that one doing a google search.
On a side note,
never rely solely on client-side validation, make sure you are checking on the server-side as well.
