From 985493dca36e0960cde619565ac8ef2f8a27c6b9 Mon Sep 17 00:00:00 2001 From: Aaron Date: Sat, 1 Aug 2020 21:30:43 -0700 Subject: [PATCH] Fix regex, make + not optional --- drfpasswordless/serializers.py | 4 ++-- tests/models.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drfpasswordless/serializers.py b/drfpasswordless/serializers.py index af40098..94b4fe3 100644 --- a/drfpasswordless/serializers.py +++ b/drfpasswordless/serializers.py @@ -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) @@ -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.") diff --git a/tests/models.py b/tests/models.py index 935d88c..8bf3795 100644 --- a/tests/models.py +++ b/tests/models.py @@ -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.")