jQuery: how to stop error messages duplicating?
<p>Please could someone help with the following?</p>

<p>I have a simple validation plugin that does what I want except if you press the submit button initially (with nothing entered) and then do it again, and again it will display the error message again and again. However, if you enter something into one or more fields it doesnt do this.</p>

<p><strong>How can I stop the error message being duplicated?</strong></p>

<p><em>PLEASE NOTE: I'm not interested in other plugins out there so that wont answer the question.</em></p>

<p>Heres the code:</p>

<pre><code>(function($) {
$.fn.simplevalidation = function(settings){

    var config = {
        errorElement: 'em',
        errorClass: 'error',
        completeElement: 'div',
        completeClass: 'complete',
        errorText: '{label} is a required field.',
        emailErrorText: 'Please enter a valid {label}',
        ajaxRequest: true, 
        completeCallback: function($el) {
        var formData = $el.serialize();
        alert('Insert Team Member: ' + formData);
        }
    }

    if(settings) $.extend(config, settings);

    return this.each(function() {
        var $this = $(this),
                o = $.meta ? $.extend({}, config, $this.data()) : config,
                errorMsgType = o.errorText.search(/{label}/);

        // on form submission
        $this.bind('submit', function(e) {

            var hasError = false;

            // hide any errors showing
            $this.find(o.errorClass).remove();

            // get all required inputs
            $this.find(':input.required').each(function(){

                var $input = $(this),
                    fieldValue = $.trim($input.val()),
                    labelText = $input.siblings('label').text(),
                    errorMsg = '';

                // check if empty
                if(fieldValue == '') {
                    errorMsg = o.errorText.replace('{label}',labelText);
                    hasError = true;
                }

                // check if valid email
                if($input.hasClass('email')){
                    if(!(/^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/.test(fieldValue))){
                        errorMsg = o.emailErrorText.replace('{label}',labelText);
                        hasError = true;
                    } 
                }

                // if there is an error then display it
                if(errorMsg != ''){
                    $input.after('&lt;'+o.errorElement+' class="'+o.errorClass+'"&gt;' + errorMsg + '&lt;/'+o.errorElement+'&gt;');
                } else {
                    $input.after('&lt;'+o.completeElement+' class="'+o.completeClass+'"&gt;&lt;/'+o.completeElement+'&gt;');
                }
            });

            // if errors
            if(hasError){ 
                e.preventDefault();
            }else if(o.completeCallback !== ''){ // if callback
                o.completeCallback($this);
                if(o.ajaxRequest) { //if ajax request
                    e.preventDefault();
                }
            }

        });

    });
};
</code></pre>

<p>})(jQuery);</p>
