There are a variety of ways to implement this. Here is one.
The relevant HTML would look like this:
<div><input type="text" id="myInput" /></div>
The jQuery would be something like this:
// probably within your jQuery(document).ready(...) function:
// bind a change event handler to your input
jQuery("#myInput").bind("change", function(e) {
var $this = jQuery(this);
var re = /[a-z]/; // here's your regex
var imgSrc = "blank.gif";
if (re.test(jQuery(this).val())){
// this is a successful match - green
imgSrc = "green.gif";
} else {
// this is not a match - red
imgSrc = "red.gif";
}
// make sure we have an image before our input:
if(!$this.prev().is("img")) { $this.before("img"); }
// set the image to green
$this.prev().attr("src", imgSrc);
});
Edit: bug fix + comments