I need a Django Form Field to support US or International phone numbers. Does one exist? How could you validate US phone #'s or int'l ones.
+3
A:
Check out Django's "local flavor packages": http://docs.djangoproject.com/en/dev/ref/contrib/localflavor/#united-states-of-america-us
lazerscience
2010-06-24 14:57:38
Can you create a field that will validate US or Int'l #'s at the same time?
MikeN
2010-06-24 17:28:05
Not out of the box, you would have to make your own field class or use a regex field as mentioned here! Subclassing an exisiting field and overriding it's clean method shouldn't be the big deal, look at this example: http://code.djangoproject.com/browser/django/trunk/django/contrib/localflavor/us/forms.py#L29
lazerscience
2010-06-24 18:50:06
+1
A:
lazerscience's answer is correct, but I want to give an alternative as you also asked for International Phone Numbers.
Just use a RegexField with a regular expression for the format you want, for the most types of phone numbers this can easily be googled. In fact, many local flavor fields are based on a RegexField.
But use the Local Flavor packages if it suits all your needs!
KillianDS
2010-06-24 16:14:28