Projet

Général

Profil

0005-qommon-misc-extend-validate_phone_fr-validation-scop.patch

Paul Marillonnet, 25 octobre 2022 10:30

Télécharger (1,44 ko)

Voir les différences:

Subject: [PATCH 5/6] qommon/misc: extend validate_phone_fr validation scope
 (#69838)

 wcs/qommon/misc.py | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
wcs/qommon/misc.py
824 824

  
825 825

  
826 826
def validate_phone_fr(string_value):
827
    if not re.match(r'^0[\d\.\s]+$', string_value):
828
        # leading zero, then digits, dots, or spaces
829
        return False
830
    return len([x for x in string_value if is_ascii_digit(x)]) == 10
827
    valid = False
828
    # local french phone number
829
    if re.match(r'^0[\d\.\s]+$', string_value) and len([x for x in string_value if is_ascii_digit(x)]) == 10:
830
        valid = True
831
    # internal E.164 format with '+33' prefix
832
    elif (
833
        re.match(r'^\+33[\d\.\s]+$', string_value)
834
        and len([x for x in string_value if is_ascii_digit(x)]) == 11
835
    ):
836
        valid = True
837
    # equivalent international format with '0033' prefix
838
    elif (
839
        re.match(r'^0033[\d\.\s]+$', string_value)
840
        and len([x for x in string_value if is_ascii_digit(x)]) == 13
841
    ):
842
        valid = True
843
    return valid
831 844

  
832 845

  
833 846
def validate_siren(string_value):
834
-