I’m currently using UKPhoneNumberField in one of my forms. I recently found that if I submit a London number 02081112222 (or as 020 8111 2222) it saves the number as 020 81112222 8111 in the DB. I’m not very good at debugging python so I was wondering if someone could help me track down the problem. Cheers
EDIT:
I sure it is something to do with the format_number function since I commented it out my problems go away (yes, I know it’s not a solution, just a step closer to one):
def format_number(self, value, number_spec):
# if number_spec[1] is None:
# components = (value,)
# else:
# components = []
# position = 0
# last_index = len(number_spec) - 1
# for index, chunk in enumerate(number_spec[1]):
# if index == last_index:
# components.append(value[position:])
# else:
# components.append(value[position:position+chunk])
# position += chunk
# return ' '.join(components)
return value
Debugging it is going to be hard because I have know idea what it does. (Trust me I’m really trying!! I’m just new to this whole python stuff)
The problem looks likes its caused by the following in format_number
As the code loops the second (or last -1) iteration will match, this results in the code appending 81112222 (position:) to the string rather then 8111, the 3rd iteration then adds 8111. Removing – 1 form the code solves this however I’m guessing this will affect the field in others ways.