Issue
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
Solution
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}
Answered By - user2021091
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.