1

I'm trying to write a regular expression for ng-pattern that will pass on the following cases:

.1 - Pass
.01 - Pass
0.01 - Pass
1 - Pass
1.0 - Pass
1.00 - Pass
$1.00 - Pass
$1000 - Pass
$1,000 - Pass
$1,000,000.00 Pass

11,11 - Fail
11.111 - Fail

This regular expression will pass and fail the appropriate cases on https://regex101.com/

(?=.)^\$?(([1-9][0-9]{0,2}(,[0-9]{3})*)|[0-9]+)?(\.[0-9]{1,2})?$

However when I try this:

data-ng-pattern="/^(?=.)^\$?(([1-9][0-9]{0,2}(,[0-9]{3})*)|[0-9]+)?(\.[0-9]{1,2})?$/"

I get the following error message:

 SyntaxError: Invalid regular expression: /^(?=.)^$?(([1-9][0-9]{0,2}(,[0-9]{3})*)|[0-9]+)?(\.[0-9]{1,2})?$/: Nothing to repeat

What do I need to adjust to make this work in angular?

JamesNB
  • 27
  • 13

0 Answers0