Skip to content

Commit 7fe00df

Browse files
authored
Merge pull request aaronn#67 from aaronn/feature/international-phone-regex
Fix regex, make + not optional
2 parents e757cac + 985493d commit 7fe00df

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

drfpasswordless/serializers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class MobileAuthSerializer(AbstractBaseAliasAuthenticationSerializer):
8585
def alias_type(self):
8686
return 'mobile'
8787

88-
phone_regex = RegexValidator(regex=r'^\+?[1-9]\d{1,14}$',
88+
phone_regex = RegexValidator(regex=r'^\+[1-9]\d{1,14}$',
8989
message="Mobile number must be entered in the format:"
9090
" '+999999999'. Up to 15 digits allowed.")
9191
mobile = serializers.CharField(validators=[phone_regex], max_length=17)
@@ -169,7 +169,7 @@ class AbstractBaseCallbackTokenSerializer(serializers.Serializer):
169169
Abstract class inspired by DRF's own token serializer.
170170
Returns a user if valid, None or a message if not.
171171
"""
172-
phone_regex = RegexValidator(regex=r'^\+?[1-9]\d{1,14}$',
172+
phone_regex = RegexValidator(regex=r'^\+[1-9]\d{1,14}$',
173173
message="Mobile number must be entered in the format:"
174174
" '+999999999'. Up to 15 digits allowed.")
175175

tests/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django.core.validators import RegexValidator
44
from django.db import models
55

6-
phone_regex = RegexValidator(regex=r'^\+?[1-9]\d{1,14}$',
6+
phone_regex = RegexValidator(regex=r'^\+[1-9]\d{1,14}$',
77
message="Mobile number must be entered in the format:"
88
" '+999999999'. Up to 15 digits allowed.")
99

0 commit comments

Comments
 (0)