diff options
author | Ivan Kohler <ivan@freeside.biz> | 2013-10-20 20:59:30 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2013-10-20 20:59:30 -0700 |
commit | 24f8d52f90be8e99b10734f49d451e1e70afdfbc (patch) | |
tree | bfef154c0b04325d246880db437c002fc13207d5 /FS/FS/contact_phone.pm | |
parent | 275ce0155bd34829ee97b3f0ca48228ca3c5daca (diff) |
normalize contact phone formatting
Diffstat (limited to 'FS/FS/contact_phone.pm')
-rw-r--r-- | FS/FS/contact_phone.pm | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/FS/FS/contact_phone.pm b/FS/FS/contact_phone.pm index 55cb09d..7ba8523 100644 --- a/FS/FS/contact_phone.pm +++ b/FS/FS/contact_phone.pm @@ -131,6 +131,29 @@ sub check { $self->SUPER::check; } +sub phonenum_pretty { + my $self = shift; + + #until/unless we have the upgrade strip all whitespace + (my $phonenum = $self->phonenum ) =~ s/\D//g; + + if ( $self->countrycode == 1 ) { + + $phonenum =~ /^(\d{3})(\d{3})(\d{4})(\d*)$/ + or return $self->phonenum; #wtf? + + $phonenum = "($1) $2-$3"; + $phonenum .= " x$4" if $4; + return $phonenum; + + } else { + warn "don't know how to format phone numbers for country +". $self->countrycode; + #also, the UI doesn't have a good way for you to enter them yet or parse a countrycode from the number + return $self->phonenum; + } + +} + =back =head1 BUGS |