You can set custom format on the fly like this:

Faker::Base.numerify('+90(###) ### ####')

This will solve your problem.

Answer from zeitnot on Stack Overflow
🌐
GitHub
github.com › fzaninotto › Faker › issues › 1909
Feature: phoneNumber without extension (en_US) · Issue #1909 · fzaninotto/Faker
January 27, 2020 - After running into this with the second major identity provider (Stripe first, now Google Firebase) I believe and option for a US phone number that never includes an extension is in order. Both of these providers occasionally reject phone numbers generated by Faker\Provider\en_US\PhoneNumber because of the length of inclusion of the "x".
Author   MGatner
🌐
RubyDoc
rubydoc.info › gems › faker › Faker › PhoneNumber
RubyDoc.info: Class: Faker::PhoneNumber – Documentation for faker (3.6.1) – RubyDoc.info
Produces a random cell phone number in a random format without the country code and it can have different dividers. Faker::PhoneNumber.cell_phone #=> "(836) 115-8995" Faker::PhoneNumber.cell_phone #=> "382-597-5739" Faker::PhoneNumber.cell_phone ...
🌐
GitHub
github.com › faker-ruby › faker › issues › 1112
can I have phone number without extension ? · Issue #1112 · faker-ruby/faker
I used the phone number But I got it with extension like this 772-828-3698 x8424 is there any way to have it like 772-828-3698 Thanks, Abdel
🌐
GitHub
github.com › faker-ruby › faker › issues › 1114
remove phone extension, but sometimes it come without ext · Issue #1114 · faker-ruby/faker
faker-ruby / faker Public · Notifications · You must be signed in to change notification settings · Fork 3.2k · Star 11.3k · New issueCopy link · New issueCopy link · Closed · Closed · remove phone extension, but sometimes it come without ext#1114 · Copy link · Labels · 💭 Discussion · mlotfi2005 · opened · on Jan 11, 2018 · I asked this question, but you closed it quickley. Thank you ZasMan, it wokrs but sometimes the phone number generated come without extension, applying your solution I got "972-469" which it's not a validated phone number, and my test fail.
🌐
GitHub
github.com › faker-ruby › faker › blob › main › doc › default › phone_number.md
faker/doc/default/phone_number.md at main · faker-ruby/faker
Generates a phone number in a random format without the country code and it can have different dividers. Faker::PhoneNumber.phone_number #=> "(504) 113-1705" Faker::PhoneNumber.phone_number #=> "662.291.7201" Faker::PhoneNumber.phone_number ...
Author   faker-ruby
Top answer
1 of 2
4

Unfortunately, Faker doesn't have a built-in function to do this.

You have two options.

Write functions yourself, for example:

def fake_phone_number(fake: Faker) -> str:
    return f'+91 {fake.msisdn()[3:]}'
from faker import Faker

def main():
    fake = Faker()
    print(fake_phone_number(fake))

Or create an appropriate provider and suggest adding it: https://faker.readthedocs.io/en/master/communityproviders.html

Python src MSISDN. What is MSISDN.

Or

from faker import Faker
from faker.providers.phone_number import Provider


class IndiaPhoneNumberProvider(Provider):
    """
    A Provider for phone number.
    """

    def india_phone_number(self):
        return f'+91 {self.msisdn()[3:]}'


def main():
    fake = Faker()
    fake.add_provider(IndiaPhoneNumberProvider)
    print(fake.india_phone_number())
2 of 2
3

You can use faker's hindi Indian provider, it will generate most of the numbers with +91, but not all:

Code sample with faker and factoryboy.Faker:

import factory
from faker import Faker

fake = Faker(locale="hi_IN")

fake.phone_number()

# with factory-boy's faker
class New(factory.DictFactory):

    phone = factory.Faker("phone_number", locale="hi_IN")

New()

Usage result:

print(fake.phone_number())
>> +91 9018742635
print(New())
>> {'phone': '+91 1489998444'}

If you want to ensure that every number has a +91, you need to tweak with factoryboy or wrap fake.phone_number with a parsing function.

A neat solution could be using a library called phonenumbers like this:

import phonenumbers
from faker import Faker

fake = Faker(locale="hi_IN")
number = fake.phone_number()
num_obj = phonenumbers.parse(number, "IN")
interanational_IN_number = phonenumbers.format_number(num_obj, phonenumbers.PhoneNumberFormat.INTERNATIONAL)
print(interanational_IN_number)

This should work most of the time, except with numbers starting with 091 - they should have two leading zero to be identified properly (0091), fix that corner case, and you should be good to go.

🌐
GitHub
github.com › faker-js › faker › issues › 1542
Add phone.number generation options · Issue #1542 · faker-js/faker
November 7, 2022 - an international telephone number. It would be nice if it is possible to be more specific which addresses should be generated. ... It is not a goal to generate phone numbers that are normalized beyond the given options.
Author   ST-DDT
Find elsewhere
🌐
FakerJS
fakerjs.dev › api › phone.html
Phone | Faker
Generates a random phone number. ... faker.phone.number() // '961-770-7727' faker.phone.number({ style: 'human' }) // '555.770.7727 x1234' faker.phone.number({ style: 'national' }) // '(961) 770-7727' faker.phone.number({ style: 'international' }) // '+15551234567'
🌐
RubyDoc
rubydoc.info › github › faker-ruby › faker › Faker › PhoneNumber
RubyDoc.info: Class: Faker::PhoneNumber – Documentation for faker-ruby/faker (main) – RubyDoc.info
Produces a random cell phone number in a random format without the country code and it can have different dividers. Faker::PhoneNumber.cell_phone #=> "(836) 115-8995" Faker::PhoneNumber.cell_phone #=> "382-597-5739" Faker::PhoneNumber.cell_phone ...
🌐
GitHub
github.com › faker-js › faker › discussions › 2577
phone number · faker-js/faker · Discussion #2577
December 13, 2023 - FFR: https://fakerjs.dev/api/phone.html#number · The format parameter and the regex method have similar capabilities but slightly different syntax. As for why: Because we plan to improve the method to generate the format that you need directly without having to pass a format.
Author   faker-js
🌐
HexDocs
hexdocs.pm › faker › Faker.Phone.EnUs.html
Faker.Phone.EnUs — Faker v0.18.0 - Log in
The allowed ranges for xxxx (subscriber number) are [0–9] for each of the four digits. ... iex> Faker.Phone.EnUs.area_code() "825" iex> Faker.Phone.EnUs.area_code() "246" iex> Faker.Phone.EnUs.area_code() "681" iex> Faker.Phone.EnUs.area_code() "683" ... iex> Faker.Phone.EnUs.exchange_code() "503" iex> Faker.Phone.EnUs.exchange_code() "845" iex> Faker.Phone.EnUs.exchange_code() "549" iex> Faker.Phone.EnUs.exchange_code() "509" ... iex> Faker.Phone.EnUs.extension...
🌐
Stack Overflow
stackoverflow.com › questions › 76482305 › faker-generate-a-phone-number
java - Faker generate a phone number - Stack Overflow
How to configure the generation so that the number is output in the format +7916xxxxxxxx · Faker faker = new Faker(new Locale("ru", "Moscow")); String phone = faker.phoneNumber().cellPhone();
🌐
Tabnine
tabnine.com › home page › code › javascript › faker
faker.phoneNumber JavaScript and Node.js code examples | Tabnine
const defineFakeUser = () => ({ 'first name': faker.name.firstName(), 'last name': faker.name.lastName(), 'title': faker.name.title(), 'phone': faker.phone.phoneNumber(), 'homepage': faker.internet.url(), 'avatar': faker.internet.avatar(), 'address': faker.address.streetAddress(), 'address 2 (optional)': faker.address.secondaryAddress(), 'state': faker.address.state(), 'zip code': faker.address.zipCode(), 'city': faker.address.city(), }) FakerStatic.name · FakerStatic.random · FakerStatic.internet · email · firstName · findName, FakerStatic.lorem, FakerStatic.address, number, uuid, city, FakerStatic.date, avatar, FakerStatic.commerce, FakerStatic.phone, userName, words, arrayElement ·
🌐
RubyDoc
rubydoc.info › github › faker-ruby › faker › Faker › PhoneNumber.phone_number
RubyDoc.info: Method: Faker::PhoneNumber.phone_number – Documentation for faker-ruby/faker (main) – RubyDoc.info
Libraries » faker-ruby/faker (main) » Index » Faker » PhoneNumber » phone_number ... Produces a phone number in a random format without the country code and it can have different dividers.
🌐
Wormiecorp
wormiecorp.github.io › Faker.NET.Portable › docs › examples › phone
Faker.NET.Portable - Phone Examples
NOTES: By adding using Faker;, all Faker. prefixes in the examples can be removed. Will generate a random cell phone number (mobilephone). ... Will generate a random phone extension.