diff --git a/contest/forms.py b/contest/forms.py index 0cc4965..43c0a47 100644 --- a/contest/forms.py +++ b/contest/forms.py @@ -6,7 +6,7 @@ from crispy_forms.layout import Submit from django.urls import reverse from .models import User, Reference, QSO -from .validators import CallUsernameValidator +from .validators import CallUsernameValidator, CallLogValidator class CustomUserCreationForm(UserCreationForm): class Meta: @@ -62,7 +62,7 @@ class QSOForm(forms.ModelForm): raise forms.ValidationError("Reference already exists") try: - CallUsernameValidator()(data) + CallLogValidator()(data) except forms.ValidationError: raise forms.ValidationError("Enter a valid callsign (1-2 chars, a number, 1-4 chars, maybe a /[A-Z])") diff --git a/contest/validators.py b/contest/validators.py index 22b5f95..687c0b4 100644 --- a/contest/validators.py +++ b/contest/validators.py @@ -9,10 +9,20 @@ import re @deconstructible class CallUsernameValidator(validators.RegexValidator): #regex = r'^[\w.@+-]+$' - regex = r'^(?:[A-Z]+/)?[A-Z]{1,2}[0-9][A-Z]{1,4}(?:-[0-9])?(?:/p)?$' + regex = r'^(?:[A-Z]+/)?[A-Z]{1,2}[0-9][A-Z]{1,4}(?:-[0-9])??$' message = _( - 'Enter a valid Callsign as Username, ALL UPPERCASE, if needed with /A /B,' - 'e.g. DL7BST, DN1BER/A, DL/OE1FOO' + 'Enter a valid Callsign as Username, ALL UPPERCASE, if needed with -1 / -2,' + 'e.g. DL7BST, DN1BER-1, DL/OE1FOO.' + ) + flags = re.ASCII if six.PY3 else 0 + +@deconstructible +class CallLogValidator(validators.RegexValidator): + #regex = r'^[\w.@+-]+$' + regex = r'^(?:[A-Z]+/)?[A-Z]{1,2}[0-9][A-Z]{1,4}(?:-[0-9])?(?:/[A-Z]{1,3})?$' + message = _( + 'Enter a valid callsign, ALL UPPERCASE, if needed with -1 / -2,' + 'e.g. DL7BST, DN1BER-1, DL/OE1FOO, DN1FTW-1/p' ) flags = re.ASCII if six.PY3 else 0