Regularexpression allow greater than 0.00

Asked

Viewed 101 times

0

False value:

0,00 -- false

True value:

0,01 -- true
0,10 -- true
1,00 -- true
10,00 -- true
100,00 - true
1.000,00 -- true
10.000,00 -- true
100.000,00 --true
1.000.000,00 -- true
10.000.000,00 -- true
100.000.000,00 -- true
1.000.000.000,00 -- true

Meaning it can only be greater than 0.00.

Follows the code:

[RegularExpression(@"^(?!0,00)\d+\,\d{0,2}$", ErrorMessage = "Inválido")]

The problem is 1,000.00

Some solution ?

2 answers

1

Solution

^(?!^(0{1,3}\.?)+(,00)?$)(\d{1,3}\.?)+(,\d\d?)?

Be Running on REGEX101

  • I particularly disliked the thousand separator detection. It seems that it can detect 10.0.0.125,98

  • 1

    @Jeffersonquesado I didn’t want to be so pragmatic, but it’s possible, if you want, I can see to do.

1


Just change your code:

Barter:

^(?!0,00)\d+\,\d{0,2}$

For:

^(?!0,00)\s*(?:[1-9]\d{0,2}(?:\.\d{3})*|0)(?:,\d{1,2})?$

Segue regex online:

https://regex101.com/r/ALgFkf/1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.