Adding phone number field to user registration

775 views
Skip to first unread message

Dennis W

unread,
Nov 10, 2015, 8:47:41 PM11/10/15
to django-oscar
I'm adding a phone number field to the EmailUserCreationForm I just added a PhoneNumberField to my user model like this : 

phone_number = PhoneNumberField(default = "555-555-1212")

then i added the field to EmailUserCreationForm to make it required in the registration form like this : 

phone_number = forms.CharField(label=_('Phone Number'))

and then in meta:
    fields = ('phone_number') 


everything shows up fine in the form but the phone number will only validate if it has a "+" in front of the number. So "213-555-1212" won't validate, 
but "+1-213-555-1212" will validate. Can anyone tell me how to get this to work without the +1 ? Am I missing a country setting in my settings file or something ? 

femi ogundayo

unread,
Nov 11, 2015, 3:54:44 AM11/11/15
to django-oscar
Why dont you set the phone number field to an integer field rather than a character field?

Dennis W

unread,
Nov 11, 2015, 3:20:44 PM11/11/15
to django-oscar
well because i read somewhere in the docs that it uses django-phonenumber-field which uses charfield. So i used a charfield for the form? I guess it's looking for a country code that needs to be passed to it. I think i will have to make another mixin like the one used in the address form. I will report back if i decide to go through with it. but for right now I just made the phonenumber field on the address form mandatory. 
Reply all
Reply to author
Forward
0 new messages