2

I use a regexp validator and I want to restrict the use of anything but the pattern:

5414.1;123;412.1;41241;...

I tried to use [0-9;\.]* but I can't make it match only patterns which contain one(1) point after the text and before ;.

I tested using http://regexpal.com/.

Jacob Krieg
  • 2,834
  • 15
  • 68
  • 140

4 Answers4

4

If the data has to end with a ;:

 (-?\d+(\.\d+)?\;)+

Otherwise:

 (-?\d+(\.\d+)?)(;-?\d+(\.\d+)?)*;?

These will not allow empty input but you can achieve that behaviour by replacing the + in the first example with * and by wrapping the second one in (...)?.

xsc
  • 5,983
  • 23
  • 30
4
^(\d+(\.\d+)?;)+$

the ^$ will prevent accepting a part of the string

2

you could also use this pattern

^(?:-?\d+[.;]?)+$
alpha bravo
  • 7,838
  • 1
  • 19
  • 23
1

That is not perfect, too, but is already in the near... for example it allowed -01.5.

((-|)[0-9]+(\.[0-9]*[1-9]|)\;)*(-|)[0-9]+(\.[0-9]*[1-9]|)

Instead an (x|) -like expression you can also use x?. (Thanks @OGHaza)

peterh
  • 11,875
  • 18
  • 85
  • 108