Home > Blockchain >  Faker ID number with flexible format
Faker ID number with flexible format

Time:03-30

I'm looking for a way to generate codes/ids in my specs. I found barcodes, codes, and id numbers. None of these quite fit my purpose...or if I use them they will be misleading for the type of code I'm actually generating. Is there a generator that allows for a format specifier? For example, I'd like to generate a string with digits and dashes in a specified sequence, like #####-###-####-#####, for example.

CodePudding user response:

Faker's numerify, letterify, and bothify seem like what you're looking for:

Faker::Base.numerify('###-###') # "203-099"
Faker::Base.letterify('???-???') # "ADB-VMZ"
Faker::Base.bothify('???-###') # "ISE-485"

Docs

  • Related