def METHOD_NAME(self):
    filename_type = self.data['filename_type']
    filename = self.data['filename']
    if filename_type == 'REX':
        try:
            re.compile(filename)
        except re.error as e:
            msg = str(e)
            raise forms.ValidationError('Given filename is not a valid regular expression. Error: "%s".' % (msg))
    return filename_type