I have an error checking function that is just running me in circles.
function emailValUReq(v, noRet) {
    var textReg = /[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?/;
    if (!v.val()) {
        if (noRet == null) {
            v.nextAll('.errText').html('<br>! Required Field');
        }
        return 1;
    } else if (!textReg.test(v.val())) {
        if (noRet == null) {
            v.nextAll('.errText').html('<br>! Invalid Entry');
        }
        return 1;
    } else {
        $data = new Object;
        $data['email'] = v.val();
        $data['id'] = v.data('cur');
        $.ajax({
            type: "POST",
            url: "/modules/data/dup_check.php",
            data: $data,
            success: function (r) {
                if (r == 'ok') {
                    v.nextAll('.errText').empty();
                    return 0;
                } else {
                    if (noRet == null) {
                        v.nextAll('.errText').html('<br>! An account already exists for this email');
                    }
                    return 1;
                }
            }
        });
    }
}
This function works perfectly overall. It returns 1 on an error, 0 when a value is correctly formatted and unique. The problem comes in when I try to 'add up' the errors from multiple functions.
(area and noRet are passed in)
var vErr=0;
    area.find('.emailvalureq:visible').each(function () {
        vErr += emailValUReq($(this), noRet);
    });
When the input field is empty, or when it is incorrectly formatted, this works properly. As soon as the $.ajax call is fired within the validation script, it seems that the delay messes everything up and vErr ends up being a NaN value.
I have tried doing this as follows, with the same result:
var vErr=0;
area.find('.emailvalureq:visible').each(function () {
    var ve1 = emailValUReq($(this), noRet);setTimeout(function(){vErr+=ve1;},1000);
});
I'm going to be at a family wedding for a couple hours, so I won't be able to respond to any questions / suggestions until later tonight - but any help is appreciated!
 
    