I'm making a faker plugin ( jQuery-Faker ) in jQuery which generates fake data for fill in the form corresponding to their field name.
So I want to generate phone number using regular expression /\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/
So is there any way to do this?
2 Answers
You might want to look at the string from regex family of libraries.
Here is the one for javascript
As seen in the README you can do
var RandExp = require('randexp');
var phoneGenerator = new RandExp(/\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/);
phoneGenerator.gen(); // =>