-3
extension PriceValidator on String {
  bool  isValidPrice () {
    return RegExp(r'^(\d{1,3}(\.\d{3})*|(\d+))*(\.\d{3})$').hasMatch(this);
  }
}

I used this regular expression to get me this data when publishing a product:

5,000

10,000

245,000

1,000,000

25,000,000

240,000,000

and it gives me this data:

5, 10, 245, 1,25,240,

1 Answers1

0

Your regex is looking for numbers that have a period as a thousands seperator but your data is using commas as thousand seperators. You need to replace \. with ,:

^(\d{1,3}(,\d{3})*|(\d+))*(,\d{3})$

VvdL
  • 2,799
  • 1
  • 3
  • 14
  • For some reason, the comma is not activated on the cell phone keyboard, only the period. I need you to stop throwing me these prices in dollars, 5.00, 150.00 – esneider bertel Nov 18 '22 at 16:32