title: Django: Checking CharField format in form with a regular expression
body: <pre><code>class CapaForm(forms.Form):
      capa = forms.CharField(required=False)
  </code></pre>
  
  <p>Upon form submission I want to check the format of the <code>capa</code> field. I want to require the user to enter the capa format correctly as 6 numbers, a dash, and two numbers. (######-##)</p>
  
  <pre><code>def search(self):
      capa = self.cleaned_data.get('capa', None)
  
      if ("\d{6}\-\d{2}" or None) not in capa:
              raise forms.ValidationError("CAPA format needs to be ######-##!")
  </code></pre>
  
  <p>It's currently not letting me submit a correctly formatted capa and throws the ValidationError. I think the problem is I'm trying to compare a regular expression to an object. How can I check the format of the 'capa' the user tries to submit?</p>
  
  <p>*********UPDATE</p>
  
  <p>Everything is working now EXCEPT when I type the wrong format in the CAPA field. I get the error <code>The view incidents.views.index didn't return an HttpResponse object. It returned None instead.</code> Is this related to the changes I made?</p>
  
  <pre><code>from django.core.validators import RegexValidator
  my_validator = RegexValidator("\d{6}\-\d{2}", "CAPA format needs to be ######-##.")
  
  class CapaForm(forms.Form):
      capa = forms.CharField(
          label="CAPA",
          required=False, # Note: validators are not run against empty fields
          validators=[my_validator]
          )
  
  def search(self):
      capa = self.cleaned_data.get('capa', None)
      query = Incident.objects.all()
      if capa is not '':
              query = query.filter(capa=capa)
      return(query)
  </code></pre>