fix issue with new caledonie phone numbers

apikeys
Razmig Sarkissian 4 months ago
parent 2ef88b0803
commit d6a754b053
  1. 23
      tournaments/forms.py

@ -77,10 +77,10 @@ class SimpleCustomUserCreationForm(UserCreationForm):
def clean_phone(self):
phone = self.cleaned_data.get('phone')
if phone:
# Remove all spaces
phone = phone.replace(' ', '')
# Basic regex for phone numbers, matching common formats
if not re.match(r"^\+?\d{10,15}$", phone):
# Remove all spaces, dots, dashes, and parentheses
phone = re.sub(r'[\s\.\-\(\)]', '', phone)
# Basic regex for phone numbers, allowing 6-15 digits for international numbers
if not re.match(r"^\+?\d{6,15}$", phone):
raise forms.ValidationError("Entrer un numéro de téléphone valide.")
return phone
@ -181,10 +181,9 @@ class TournamentRegistrationForm(forms.Form):
def clean_mobile_number(self):
mobile_number = self.cleaned_data.get('mobile_number')
if mobile_number:
# Basic regex for mobile numbers, matching common formats
# Remove spaces from the number first
mobile_number = mobile_number.replace(' ', '')
if not re.match(r"^\+?\d{10,15}$", mobile_number):
# Remove spaces, dots, dashes, and parentheses from the number first
mobile_number = re.sub(r'[\s\.\-\(\)]', '', mobile_number)
if not re.match(r"^\+?\d{6,15}$", mobile_number):
raise forms.ValidationError("Entrer un numéro de téléphone valide.")
return mobile_number
@ -292,10 +291,10 @@ class ProfileUpdateForm(forms.ModelForm):
def clean_phone(self):
phone = self.cleaned_data.get('phone')
if phone:
# Remove all spaces
phone = phone.replace(' ', '')
# Basic regex for phone numbers, matching common formats
if not re.match(r"^\+?\d{10,15}$", phone):
# Remove all spaces, dots, dashes, and parentheses
phone = re.sub(r'[\s\.\-\(\)]', '', phone)
# Basic regex for phone numbers, allowing 6-15 digits for international numbers
if not re.match(r"^\+?\d{6,15}$", phone):
raise forms.ValidationError("Entrer un numéro de téléphone valide.")
return phone

Loading…
Cancel
Save