import re


def validate(data, validators):
    """
    Run a set of validators against a dict (typically post parameters)
    :data: dictionary to be validated
    :validators: array of validators
    :return: dict of errors - keyed with the fieldnames
    """
    errors = {}
    for validator in validators:
        key = validator["key"]
        value = data.get(key) or ""
        if key not in errors:  # we only want one error per field
            if not re.compile(validator.get("re", ".+")).match(value):
                errors[key] = validator["message"]
    return errors