So, without resorting to a brute-force while loop that has no upper bound, and without introducing an upper bound for such trivial problems, what better ways are there to generate valid phone numbers accepted by the validator itself? from phonenumber_field.validators import validate_international_phonenumberįrom re. This is also called concatenation.We can also repeat the elements in a tuple for a given number of times using the. '+1-91' # Obviously wrong, it has 911 in it Examples: The generated random phone numbers would looklike: 9980231467 8726189362 Implementation: Python3 import random as r phno phno.append (r. The remaining 9 digits will also be generated using the randint () method. > a = functools.partial(random.randint, 0, 9) The first digit should start with 9 or 8 or 7 or 6, we will use randint () method. Within the project are vast lists of custom validation rules, for which naive approach like this will not be sufficient: > import functools My project uses python-phonenumbers and django-phonenumber-field for phone number validation. Not a duplicate of Making random phone number xxx-xxx-xxxx
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |