Skip to content

Commit

Permalink
chore: update PhonenumberSerializer docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-canon committed Jul 16, 2024
1 parent ea0c325 commit c50c432
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions openedx/core/djangoapps/user_api/accounts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,23 @@

class PhoneNumberSerializer(serializers.BaseSerializer): # lint-amnesty, pylint: disable=abstract-method
"""
Class to serialize phone number into a digit only representation
Class to serialize phone number into a digit only representation.
This serializer removes all non-numeric characters from the phone number,
allowing '+' only at the beginning of the number.
"""

def to_internal_value(self, data):
"""Remove all non numeric characters in phone number"""
"""
Remove all non-numeric characters from the phone number.
Args:
data (str): The input phone number string.
Returns:
str or None: The cleaned phone number string containing only digits,
with an optional '+' at the beginning.
"""
return re.sub(r'(?!^)\+|[^0-9+]', "", data) or None


Expand Down

0 comments on commit c50c432

Please sign in to comment.