M
Michael_Burgess
Hi there,
I'm using the following regex validator:
^\d{0,4}.?\d{0,2}$
This is to validate that a text box has 0-4 numbers, possible followed
by a decimal point and possibly followed by 2 decimal places.
For instance, the following are valid.......
0.45
200
3.89
..67
4667
255.98
etc. I've got it all working by handling all key-press events on the
text box apart from control keys and 0-9 plus the decimal point. On
pressing a key, I create a temp string and store the current text box
contents into it, then append the wanted number/decimal to the end and
apply the regex validator to it, handling the keypress if it doesn't
match. Got the regular expression working a treat too. I've got a lost
focus event on the text box, that auto applies a floating point format
with string.Format and {0:F}.
That all works fine too.
My only niggle is...............
The regex allows integer numbers of 5, 6 and 7 in length. I'd like to
stop this if I can but can't work it out - any ideas?!?
Ultimately, this isn't a MAJOR problem, but it'd be slick if I could
sort it. I was about to code all this out instead of using regex and
I've achieved in 3 lines what would have probably taken 50 or so! Spot
on.
Please help! Want to get this integrated into my work tomorrow!
I'm using the following regex validator:
^\d{0,4}.?\d{0,2}$
This is to validate that a text box has 0-4 numbers, possible followed
by a decimal point and possibly followed by 2 decimal places.
For instance, the following are valid.......
0.45
200
3.89
..67
4667
255.98
etc. I've got it all working by handling all key-press events on the
text box apart from control keys and 0-9 plus the decimal point. On
pressing a key, I create a temp string and store the current text box
contents into it, then append the wanted number/decimal to the end and
apply the regex validator to it, handling the keypress if it doesn't
match. Got the regular expression working a treat too. I've got a lost
focus event on the text box, that auto applies a floating point format
with string.Format and {0:F}.
That all works fine too.
My only niggle is...............
The regex allows integer numbers of 5, 6 and 7 in length. I'd like to
stop this if I can but can't work it out - any ideas?!?
Ultimately, this isn't a MAJOR problem, but it'd be slick if I could
sort it. I was about to code all this out instead of using regex and
I've achieved in 3 lines what would have probably taken 50 or so! Spot
on.
Please help! Want to get this integrated into my work tomorrow!