from django.forms import RegexField

class RegexFormatField(RegexField):
     
    def __init__(self, *args, **kwargs):
        if 'format' in kwargs:
            self.format = kwargs['format']
            del kwargs['format']
        super(RegexFormatField, self).__init__(*args, **kwargs)
        
    def clean(self, value):
        value = super(RegexFormatField, self).clean(value)
        if self.format is not None:
            value = self.format % self.regex.match(value).groupdict()
        return value