Getting Error with Django Phone Number Form Field
<p>I'm building a Django form that includes a phone number field.  I've been referring to these two SO questions to understand how to do it: <a href="http://stackoverflow.com/questions/19130942/whats-the-best-way-to-store-phone-number-in-django-models">1</a>, <a href="http://stackoverflow.com/questions/6478875/regular-expression-matching-e-164-formatted-phone-numbers">2</a>.  I've created this form field:</p>

<pre><code>class ContactForm(forms.Form):
    phone = forms.RegexField(
        regex = r'^\+?[1-9]\d{1,14}$',
        #regex = r'\+?\d{10,14}$',
        error_messages = {'required', 'Phone number required'},
        widget = forms.TextInput(attrs={'class': 'form-control'})
    )
</code></pre>

<p>I display the field in my template:</p>

<pre><code>&lt;div&gt;
    &lt;label for="id_phone"&gt;Your Phone Number&lt;/label&gt;
    {{ form.phone.errors }}
    {{ form.phone }}
&lt;/div&gt;
</code></pre>

<p>I understand what the regexes are doing and they look correct to me.  However, I'm getting this error if I use either one of them:</p>

<pre><code>ValueError at /business/contact/
dictionary update sequence element #0 has length 8; 2 is required
...
Exception Location: /srv/http/swingerpixels.com/venvs/dev/local/lib/python2.7/site-packages/django/forms/fields.py in __init__, line 125
(stacktrace...)
widget = forms.TextInput(attrs={'class': 'form-control'})
super(RegexField, self).__init__(max_length, min_length, *args, **kwargs)
super(CharField, self).__init__(*args, **kwargs)
messages.update(error_messages or {})
(end of stacktrace)
</code></pre>

<p>Can anyone see what's causing this error?  It seems to be caused by the regexes.</p>

<p>I just discovered the error.  It's in this line:</p>

<pre><code>error_messages = {'required', 'Phone number required'},
</code></pre>

<p>I needed to replace the "," with a ":":</p>

<pre><code>error_messages = {'required': 'Phone number required'},
</code></pre>

python django django-forms