-5
I need a regex that validates numbers, commas, and period it must contain numbers and if it contains a point or comma, have only one of the two, 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 that expression '/[ 0-9,. ]/g' it blocks anything that is not number of dots or commas, but you can put as many as you want (the dots and commas).
Ok. What did you do? What was the result obtained? Do you know how to elaborate a regular expression?
– Woss
I need a regex q do this, I know only the basics about preparing regex.
– Eduardo Bobato
Then check with the basics you have and try to do it first. If you want to test, I recommend using sites like https://regex101.com/. If you still can’t, you can come back here and [Edit] the question, adding your attempt and what the result was. I also recommend that you add all possible cases to your description as it is not clear whether
,1
would be a valid value (even having numbers and only a comma), or1,
.– Woss