Skip to Content
๐ŸŽฒ Welcome to RandBox - Powerful JavaScript Random Data Generation Library! Learn More

string

// usage randBox.string() randBox.string({ length: 5 }) randBox.string({ min: 5 }) randBox.string({ max: 50 }) randBox.string({ min: 5, max: 20 }) randBox.string({ pool: 'abcde' }) randBox.string({ alpha: true }) randBox.string({ numeric: true }) randBox.string({ casing: 'lower' }) randBox.string({ symbols: true })

Return a random string.

randBox.string(); => 'Z&Q78&fqkPq'

By default it will return a string with random length of 5-20 characters and will contain any of the following characters.

'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()[]'

Can optionally specify a length and the string will be exactly that length.

randBox.string({ length: 5 }); => 'YN%fG'

Can optionally specify a min and the string will have a minimum length

randBox.string({ min: 5 }); => '6(Ow1wF)qjUm%W)B2[Q]'

Can optionally specify a max and the string will have a maximum length

randBox.string({ max: 20 }); => 'k7fubkfMS@gs#E'

Can optionally specify a pool and the string will be generated with characters only from that pool.

randBox.string({ pool: 'abcde' }); => 'cccdeeabedebb'

Of course these options can also be combined, using length or min and max.

randBox.string({ length: 5, pool: 'abcde' }); => 'cbbdc'
randBox.string({ min: 5, max: 20, pool: 'abcde' }); => 'ebddceaaceeda'

All the options for randBox.character() are supported:

randBox.string({ length: 8, casing: 'upper', alpha: true, numeric: true }); => '3THK7GB1'
Last updated on: