I am hoping to find someone here which can give me a hand with some regex I need to modify.
This regex is being used in JavaScript for some validation:
/^([A-Z]{3} [0-9]+\.[0-9]{1,2}(, )?)+$/
This will correctly validate the following values:
EUR 20.3, USD 9.0
GBP 8.8
I would like to modify the regex to also accept negative values such as:
EUR -20.3, USD -9.0
I thank you for your help :)
Regards Gabriel
I am hoping to find someone here which can give me a hand with some regex I need to modify.
This regex is being used in JavaScript for some validation:
/^([A-Z]{3} [0-9]+\.[0-9]{1,2}(, )?)+$/
This will correctly validate the following values:
EUR 20.3, USD 9.0
GBP 8.8
I would like to modify the regex to also accept negative values such as:
EUR -20.3, USD -9.0
I thank you for your help :)
Regards Gabriel
Share Improve this question edited Apr 7, 2011 at 9:49 Noufal Ibrahim 72.9k13 gold badges140 silver badges174 bronze badges asked Apr 7, 2011 at 9:46 Gabriel SpiteriGabriel Spiteri 4,97812 gold badges45 silver badges60 bronze badges3 Answers
Reset to default 5surely just add in:
-?
which should optionally match '-'
/^([A-Z]{3} -?[0-9]+\.[0-9]{1,2}(, )?)+$/
In the exact same way you check for the a ,
but xith negative signe -
Try something like this ([A-Z]{3} -?[0-9]+.[0-9]{1,2},?)+
try this:
/^([A-Z]{3} -?[0-9]+(\.[0-9]{1,2})?,?)+$/
the decimal places are now optional
GBP -1, GBP -1.1 should be valid