Hi all, I see in docs.djangoproject.com/en/dev/ref/validators/ how to include validators in a form field, but I have a field that needs to be validated with a regular expression determined by another field. Please help me call RegexValidator explicitly the right way. For one thing, I don't see how to pass the field to the validator. For another, I'm not sure exactly what to test for to determine that validation failed. The code follows:
from django import forms from django.core.validators import * class IdentForm(forms.Form): ident = forms.CharField() ident_type = forms.ChoiceField(choices=( ('EIN','Employer ID'), ('SSN','Social Security Number'), )) TYPE_CHOICES = ( ('EIN','\d{2}-\d{7}'), ('SSN','\d{3}-\d{2}-\d{4}'), ) def clean(self): cleaned_data = super(IdentForm, self).clean() ident = cleaned_data.get('ident') ident_type = cleaned_data.get('ident_type') regexp = TYPE_CHOICES[ident_type] RegexValidator([regexp]) # What's missing? # How do I pass ident to the validator? if ??????: # Do I test for existence of error message? ident = '' return cleaned_data What errors do I have? Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.