Regular Expressions
I'm having two little problems with my first attempt at regular expressions - I would like the following to determine whether user input is a certain type of numeric: 7 digits possibly followed by a decimal point and possibly 2 post decimal digits:
"^[0-9]{0,7}\.?[0-9]{0,2}$"
1. How do I specify that the 2 digits after the decimal are only appropriate if there indeed is a decimal? Currently, it allows a 9-digit number without a decimal.
2. Can I substitute variables for the 7 and 2? I tried and can't make it work - are there some special delimiters used to surround variables? e.g., I want to do something like:
"^[0-9]{0,iPreDecimalDigits}\.?[0-9]{0,iPostDecimalDigits}$"
Thanks,
Dave Doknjas
|