I'm making a call to my validate() function when the document loads, passing it an array of the following format: [field_id] => [rule], [message]
I am looping on field_id, assigning a blur function that checks the rule (which is a regexp), displaying a div if the regexp check fails... function validate(rules) { for(field in rules) { $("#"+field).blur(function() { if(!$(this).val().match(new RegExp(rules[field]["rule"])) && !$ (this).siblings('div.error-message').length) { $(this).parent().append($("<div>").addClass("error- message").html(rules[field]['message'])) } else { $(this).siblings('div.error-message').remove() } }) } } my problem is every field gets assigned the the LAST regexp in my rules array. Is there something I'm missing?