0

I have written a regex to match currency values with optional 2 decimal places, with either decimal point OR comma for EU.

^\d+((\.|,)\d{2})?$

The regex works as expected in regex101 tester: https://regex101.com/r/GrHsX0/1

But when using in javascript it's returning false regardless of match.

var patt = new RegExp("^\d+((\.|,)\d{2})?$");

var res1 = patt.test("11.33"); //should return true
var res2 = patt.test("22,44"); //should return true
var res3 = patt.test("abc"); //should return false

Here is a fiddle example: https://jsfiddle.net/t0p4ok08/

Bit puzzled as to why this is not working! Thanks in advance.

Rob C
  • 818
  • 1
  • 12
  • 26

0 Answers0