@require_GET
@never_cache
@json_view
def validate_field(request):
    data = {'valid': True}

    field = request.GET.get('field')
    value = request.GET.get('value')
    form = RegisterForm()

    try:
        form.fields[request.GET.get('field')].clean(request.GET.get('value'))
    except ValidationError, e:
        data = {
            'valid': False,
            'error': e.messages[0]
        }
    except __HOLE__:
        data = {
            'valid': False,
            'error': _('Invalid field')
        }

    if data['valid']:
        if field == 'username':
            if User.objects.filter(username=value).exists():
                data = {
                    'valid': False,
                    'error': _('This username is already taken!')
                }
        elif field == 'email':
            if User.objects.filter(email=request.GET.get('value')).exists():
                data = {
                    'valid': False,
                    'error': _('This email is already in use!')
                }

    return data
dataset/ETHPy150Open mozilla/kitsune/kitsune/users/views.py/validate_field