Issue
I need a regular expression that validates the following inputs:
-0.12-12.56
-0.12+12.56
-0.12*12.56
-0.12/12.56
12.3--12.56
12.3+-12.56
12.3*-12.56
12.3/-12.56
-0.12--12.56
-0.12+-12.56
-0.12*-12.56
-0.12/-12.56
0.12-12.56
0.12+12.56
0.12*12.56
0.12/12.56
Also it should allow all this conditions without decimal point and if decimal point is allowed then it should not be allowed more than once i.e. either between the digits or at start of an operand.
The minus sign should also be optional before the number.
Currently I am using below regular expression:
^-{0,1}[0-9.]+[+-×÷]{0,1}-{0,1}[0-9.]*$
Any help would be greatly appreciated !!!
Solution
You can try with the following regex:
/^-?\d+\.?\d+[-+*\/]-?\d+\.?\d+$/mg
Answered By - Mika Andrianarijaona
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.