All pastes #1163 Raw Edit

kevin

public text v1 · immutable
#1163 ·published 2004-09-29 04:22 UTC
rendered paste body
#
#       std_handler()
#       -------------
#       Try to guess the correct formatting for the incoming number
#
sub std_handler
{
    my $id = shift;
    return undef unless $id;

    #
    #   if the number is exactly 12 digits long and starts with a '44' then
    #   it's an internationally-specified UK number, so replace the '44' with
    #   a '0')
    #
    $id =~ s/^44/0/ if length($id) == 12;

    #
    #   if the number is exactly 11 digits and starts with a '0' then it's a
    #   UK number
    #
    if (length($id) > 10 && $id =~ /^[1-9]/) {
        #
        #       if the number is greater than 10 digits and starts with a
        #       non-zero digit then prefix with '00'
        #
        $id = "00$id";
    }
    elsif (length($id) == 10 && $id =~ /^[2-9]/) {
        #
        #       this is just a wild assumption, but if the number is exactly 10
        #       digits and starts with a number in the range 2-9 then assume it
        #       to be a North American number and prefix with '001'.
        #
        $id = "001$id"
    }

    #
    #   add the PSTN prefix and return the Caller*ID
    #
    $id = "$prefixes{pstn}$id" if $id;
    return $id;
}