Regex For Numeric Fields

-5

I need a regex that validates numbers, commas, and period it must contain numbers and if it contains a semicolon, have only one of them, and only once

1.1 - true
1,2 - true
2 - true
1..2 - false
1.2. - false
1.2.2 - false
2,3,2 - false
-2 - false
, 2 - false
2, - false

With this expression '/[^0-9,.]/g' it blocks anything that is not numbers or commas, but you can put as many times as you want (the dots and commas).

    
asked by anonymous 27.08.2018 / 18:04

1 answer

0

When asked a question here, we are supposed to already have something to guide us. Even so, I think this will be the solution. Digits 1 to 9 followed by a semicolon with 1 number or more as decimal places.

^[1-9]\d*(,\d+)?$   ----> para ,
^[1-9]\d*(\.\d+)?$  ----> para .
    
27.08.2018 / 18:12