2

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

3 Answers 3

5

surely just add in:

-?

which should optionally match '-'

/^([A-Z]{3} -?[0-9]+\.[0-9]{1,2}(, )?)+$/
Sign up to request clarification or add additional context in comments.

Comments

1

In the exact same way you check for the coma , but xith negative signe -

Try something like this ([A-Z]{3} -?[0-9]+.[0-9]{1,2},?)+

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.