I have the following regular expression (fairly simple) that is a good start, but I want to improve it and haven't found a good site to explain how to improve it.
I'd like it so that if the comma separator is used, then it has to continue to be used.
I'd like to be able to put a minus either at the beginning or end of the amount, but not both.
I'd also like it so that if the amount is for cents, the preceding zero would not be required, but the decimal with 1-2 digits would be.
Any help with this is greatly appreciate. Also, if you know a good reference for learning regex that'd be great too.
Code:
^(0|[1-9]\d{0,2}(,?\d{3})*)(\.\d{1,2})?$
I'd like it so that if the comma separator is used, then it has to continue to be used.
I'd like to be able to put a minus either at the beginning or end of the amount, but not both.
I'd also like it so that if the amount is for cents, the preceding zero would not be required, but the decimal with 1-2 digits would be.
Any help with this is greatly appreciate. Also, if you know a good reference for learning regex that'd be great too.