diff --git a/freedoi/resolver/forms.py b/freedoi/resolver/forms.py index 822355c..26da0df 100644 --- a/freedoi/resolver/forms.py +++ b/freedoi/resolver/forms.py @@ -14,6 +14,12 @@ class PrefixForm(forms.ModelForm): if self.instance.pk: self.fields["prefix"].widget.attrs["readonly"] = True + def clean_suffix(self): + suffix = self.cleaned_data['suffix'] + if not suffix.isdigit() or len(suffix) < 2: + raise forms.ValidationError('Suffix must be numeric and at least four digits long.') + return suffix + class SuffixForm(forms.ModelForm): class Meta: @@ -32,6 +38,12 @@ class SuffixForm(forms.ModelForm): self.fields["suffix"].widget.attrs["readonly"] = True self.fields["prefix"].widget.attrs["readonly"] = True + def clean_suffix(self): + suffix = self.cleaned_data['suffix'] + if not suffix.isdigit() or len(suffix) < 4: + raise forms.ValidationError('Suffix must be numeric and at least four digits long.') + return suffix + class SuffixApprovalForm(forms.ModelForm): class Meta: @@ -52,6 +64,12 @@ class IdentifierForm(forms.ModelForm): self.fields["identifier"].widget.attrs["readonly"] = True self.fields["suffix"].widget.attrs["readonly"] = True + def clean_identifier(self): + identifier = self.cleaned_data['identifier'] + if not all(c.isalnum() or c in '/-' for c in identifier): + raise forms.ValidationError('Identifier must be alphanumeric or contain / or - characters only.') + return identifier + class PermissionForm(forms.ModelForm): class Meta: diff --git a/freedoi/resolver/templates/resolver/identifier_form.html b/freedoi/resolver/templates/resolver/identifier_form.html index c5d7564..562b314 100644 --- a/freedoi/resolver/templates/resolver/identifier_form.html +++ b/freedoi/resolver/templates/resolver/identifier_form.html @@ -4,6 +4,11 @@