1

I have seen many of the phone example as well as third party package for thie mobile number field. but what i want is this:

+country_code , or space (these 3 are optional) phone_number(min range number= 8, max is 13) EG: +65, 98654578

based on one of the example and it work but not to what i wanted. : What's the best way to store Phone number in Django models

phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.")
phone_number = models.CharField(validators=[phone_regex], max_length=17, blank=True) # validators should be a list

The one i made is this :

mobile_regex = RegexValidator(regex=r'^\+?1?\d{1-3}?\,?\s?\d{8-15}$', message="Phone number must not consist of space and requires country code. eg : +6591258565")

But it doesnt work. Did i do something wrong? please help me

Jin Nii Sama
  • 707
  • 1
  • 16
  • 33
  • Possible duplicate of [Regex for Mobile Number Validation](https://stackoverflow.com/questions/22378736/regex-for-mobile-number-validation) – Sayse Dec 22 '17 at 11:03

1 Answers1

3

You use a dash instead of a comma, and given your instruction you also want to capture + and country code together, this regex works for me:

^(\+\d{1,3})?,?\s?\d{8,13}

user2021091
  • 561
  • 2
  • 11