コード例 #1
0
ファイル: document.py プロジェクト: iris-dni/iris-service
def normalise_phone_number(nr):
    if not nr:
        return nr
    try:
        number = pn_parse(nr, 'CH')
        return pn_format_number(number, PhoneNumberFormat.E164)
    except NumberParseException:
        # Apparently, not all numbers are valid.
        # e.g. 'faker' (used in sample data) produces phone numbers such as
        # u'+08(2)9338238082'. In such cases, we try our own version:
        nr = nr.replace('(', '').replace(')', '').replace(' ', '')
        if nr.startswith('+'):
            return nr
        if nr.startswith('00'):
            return nr.replace('00', '+', 1)
        raise ValueError("Invalid number")
コード例 #2
0
ファイル: utils.py プロジェクト: minhaz1/iris
def normalize_phone_number(num):
    return pn_format_number(pn_parse(num, 'US'),
                            PhoneNumberFormat.INTERNATIONAL)