Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhoneNumber schema #4

Open
philfreo opened this issue Sep 4, 2014 · 2 comments
Open

PhoneNumber schema #4

philfreo opened this issue Sep 4, 2014 · 2 comments
Assignees

Comments

@philfreo
Copy link
Member

philfreo commented Sep 4, 2014

Rather than having to rely on a Mongoengine field for validating phone numbers, this should be handled at the schema level

@philfreo philfreo changed the title PhoneNumber field PhoneNumber schema Sep 4, 2014
@mattjegan
Copy link

@philfreo I may have some time to look into this. Phone numbers however can come in all shapes and sizes, making it pretty hard to comprehensively validate them all. What level of validation were you hoping for? Checking that it's just a string of numbers? or some country specifically?

@wojcikstefan
Copy link
Member

We've successfully relied in production on this validation of a custom MongoEngine PhoneField: https://github.com/closeio/flask-common/blob/5199233025b959424473588e9e999929aeaf5144/flask_common/fields.py#L140

It utilizes https://github.com/daviddrysdale/python-phonenumbers for most of the parsing/validation logic.

I haven't fully thought this through and I'm open to suggestions, but at a glance a cleancat Phone field could follow a very similar logic with a strict=False/True (where False is the default) kwarg.

Perhaps it would also be worth it to have a region kwarg, which you can then pass to phonenumber.parse. It should allow callables so that you can have a function determining the region based on the current request's context (e.g. if current_user has a specific country preference). From the phonenumbers.parse docstring:

region -- The region that we are expecting the number to be from. This
          is only used if the number being parsed is not written in
          international format. The country_code for the number in
          this case would be stored as that of the default region
          supplied. If the number is guaranteed to start with a '+'
          followed by the country calling code, then None or
          UNKNOWN_REGION can be supplied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants