1

I have regEx of each input and I'd like to show user example of correct input value.

regEx:

^\+[0-9]{1,3}\.[0-9]{10,19}

show for user:

+0.1234567890

May be anybody know plugin for my task?

Ian
  • 50,146
  • 13
  • 101
  • 111
Max Khrichtchatyi
  • 507
  • 1
  • 7
  • 14
  • You have `RegExp` object in `JavaScript`. Read this: http://www.w3schools.com/jsref/jsref_obj_regexp.asp – Harshith J.V. Apr 25 '13 at 06:10
  • 3
    Just manually give some examples. – nhahtdh Apr 25 '13 at 06:11
  • ..( And if I want to automatically? – Max Khrichtchatyi Apr 25 '13 at 06:15
  • 1
    it is most likely that a tool that could do that would not produce an expected result. should it create `+000.0000000000` or should it be `+013.0123456789` or `+900.9999999999000000000` and that is just about your simple regular expression. so in such a case it is easier to create a sample yourself. create pairs of `regex => sample` in a list so that you can easy validate your samples. – t.niese Apr 25 '13 at 06:21
  • This is an interesting idea which I did not understand at first about what you are asking for. This requires some development of custom algorithms I suppose. Its already discussed here : http://stackoverflow.com/questions/3110101/auto-generated-examples-for-regexp, http://stackoverflow.com/questions/2905229/reverse-regular-expressions-to-generate-data, http://stackoverflow.com/questions/205411/random-string-that-matches-a-regexp – Harshith J.V. Apr 25 '13 at 06:29
  • Do you want only numbers ? If so, you may try a function to genenate a random number between 2 values and concatonate to your needs ... – HamZa Apr 25 '13 at 07:52
  • @63ek So are you just after random output like this: http://phpfiddle.org/api/run/ns9-iwb (refresh page for different outcomes) – MDEV Sep 11 '13 at 09:29

1 Answers1

0

Use "source" property of the RegExp object. This property contains the text of the RegExp

var regexp = /^\+[0-9]{1,3}\.[0-9]{10,19}/;
document.write("The RegExp is: "+regexp.source);

It displays => The RegExp is : ^+[0-9]{1,3}.[0-9]{10,19}

Source: JavaScript RegExp source Property

91K00
  • 452
  • 4
  • 7