I'm trying to make a RelaxedPhoneNumber field that normalizes 
user input to an internal representation of purely digits before 
getting saved, and then presents in a particular format.  I'm 
having trouble finding where to intercept and change the value. 
I want to do it on the field level, as I have a number of phone 
numbers in various models and don't want to have to monkey with 
the save() method for each of them.

Thus, I don't care if the user types

        800.555.1212
        (800)555-1212
        800-555-1212
        8005551212

as long as I can strip out the non-digits and be left with 10 digits.

So somewhere, I need to stick in something like

        non_digit_re = re.compile(r'\D')
        :
        :
        self.data = non_digit_re.sub('', self.data)

like I have in my validator

def isValidRelaxedPhone(field_data, all_data):
        # strip out non-digit characters
        digits_only_data = non_digit_re.sub('', field_data)
        if len(digits_only_data) <> 10:
                raise ValidationError, gettext(
                        'Phone numbers must be 10 digits. "%s" is invalid.') % 
digits_only_data


I see something about a prepare() method on FormField objects 
that holds promise, but I'm not sure what type of parameter 
new_data is, and what I should be doing with it.

What am I missing here?

Thanks,

-tkc



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to