-1

Currently i have a RegEx which allows only numeric

if (/$^\d+([.]?\d{0,50})?$/.test(value)

Basically i need a RegEx which should allow

only numeric
one decimal point
one $ character

I have added $ in the existing expressing, but that does not seem to be the solution. How to achieve the above all 3 scenarios

Matarishvan
  • 2,382
  • 3
  • 38
  • 68

2 Answers2

0

If I'm understanding the question correctly, this should work:

/^(\$|\$\d+(\.\d{0,50})?)$/

This regex will accept a value of "$" as well as a numeric value with $ prefix.

caedmon
  • 106
  • 7
0

You seem to be looking for

/^\$?\d+(?:\.\d{1,50})?$/

See the regex demo

Details

  • ^ - start of a string
  • \$? - an optional $ char (must be escaped)
  • \d+ - one or more digits
  • (?:\.\d{1,50})? - an optional non-capturing group matching 1 or 0 occurrences of:
    • \. - a dot
    • \d{1,50} - one to fifty digits
  • $ - end of string.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563