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