Discussion:
[FE-discuss] InternationalPhoneNumber
Stéphane Raimbault
2008-10-16 10:55:36 UTC
Permalink
In France, the regional code is 33 (+33) so when I enter an French phone
c = InternationalPhoneNumber(default_cc=33)
c.to_python('02 43 92 34 18')
'+33-243923418'

What do you think about this test?

The associated message says:
Please enter a number, with area code, in the form +##-###-#######.

but it doesn't match the French format +## ## ## ## ## ## or +##-##########

How I can run the doctests of FormEncode?

Stephane
W-Mark Kubacki
2008-10-16 12:38:08 UTC
Permalink
Post by Stéphane Raimbault
In France, the regional code is 33 (+33) so when I enter an French phone
c = InternationalPhoneNumber(default_cc=33)
c.to_python('02 43 92 34 18')
'+33-243923418'
What do you think about this test?
It does test for an invalid return value. Telephone numbers, in international notation, have to consist of a call prefix (e.g., country code +33), directory number and finally the local part number, optionally with one (!) extension.

Your example is missing the middle part, the directory number. Unfortunately they are not explicitly written in France, thus all seem to consist of ten numbers (Monaco: eight).

Correct me if I am wrong, but you still have them: 2 is for Angers, Brest, Caen, Cherbourg, Nantes, Tours, Rouen... So your number has to be entered as follows: +33-2-43923418

If this looks too strange to you, we should consider writing a dedicated validator for French numbers.

Of course, my implementation of the IPV has its limitations. For example, the NANP (North American Numbering Plan) is missing some countries you can dial from Europe, and some other countries/governments insist on their own notation (e.g., dots or slashes instead of dashes) or have their own nomenclature (see ISO, ITU...). It is meant to suit the de-facto standard for most of FE's users.
Post by Stéphane Raimbault
How I can run the doctests of FormEncode?
In this case:
nosetests --with-doctest formencode.n
Gustavo Narea
2008-10-16 13:03:18 UTC
Permalink
Post by W-Mark Kubacki
Correct me if I am wrong, but you still have them: 2 is for Angers, Brest,
Caen, Cherbourg, Nantes, Tours, Rouen... So your number has to be entered
as follows: +33-2-43923418
If this looks too strange to you, we should consider writing a dedicated
validator for French numbers.
FWIIW, Spanish people also use +##-#########.
--
Gustavo Narea.
http://gustavonarea.net/

Get rid of unethical constraints! Switch to Freedomware:
http://softwareliberty.com/
Stéphane Raimbault
2008-10-16 14:54:31 UTC
Permalink
Extract from InternationalPhoneNumber(FancyValidator):

I propose to replace this:

for f, t in [(' ', ' '), ('--', '-'), (' - ', '-'), ('- ', '-'), (' -', '-')]:
value = value.replace(f, t)
value = value.replace(' ', '')

by

value = value.replace(' ', '')
value = value.replace('--', '-')

Simpler, faster!

Stephane
W-Mark Kubacki
2008-10-18 17:45:30 UTC
Permalink
Post by Stéphane Raimbault
value = value.replace(f, t)
value = value.replace(' ', '')
by
value = value.replace(' ', '')
value = value.replace('--', '-')
Simpler, faster!
Your suggestion would remove free spaces as well - which are regarded as delimiters in this case.
The pre-transformations require these delimiters to detect e.g., directory numbers correctly. Omitting them makes only sense in the French and Spanish numbers you've mentioned.

Shall we collect country codes (i.e., +49, +33...) for countries which tolerate numbers like +##-######## (without directory numbers) or shall I only add
Gustavo Narea
2008-10-18 18:17:50 UTC
Permalink
Post by W-Mark Kubacki
Shall we collect country codes (i.e., +49, +33...) for countries which
tolerate numbers like +##-######## (without directory numbers) or shall I
only add an option "directory_number_optional"?
I'd go for the first. If I have an application used by anyone in the world, I
wouldn't like to investigate what countries don't use directory numbers; it'd
be better if such a common functionality was provided by the framework itself.

Cheers.
--
Gustavo Narea.
http://gustavonarea.net/

Get rid of unethical constraints! Switch to Freedomware:
http://softwareliberty.com/
Loading...