Skip to content

Commit

Permalink
Fix regex, make + not optional
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronn committed Aug 2, 2020
1 parent c0482c6 commit 985493d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions drfpasswordless/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class MobileAuthSerializer(AbstractBaseAliasAuthenticationSerializer):
def alias_type(self):
return 'mobile'

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

Expand Down
2 changes: 1 addition & 1 deletion tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.core.validators import RegexValidator
from django.db import models

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

Expand Down

0 comments on commit 985493d

Please sign in to comment.