Hi everyone,
I need code to do a simple masked textbox entry for input of currency. The
requirements are...
1) Should support localization,
2) Should reject invalid keystrokes on a keystroke by keystroke basis,
3) Should reject valid keystrokes that result in an invalid currency value
(input of " $2.345" USD for example)
Nice to have would be...
4) Min / Max values
5) ability to input fractional cents / pesos etc. if desired
I can't seem to find this anyplace. I've found this type of functionality
in some of the third pary control suites, but I don't need anything as
complex / expensive as these look.
If I have to write it myself, I'm open to sugestions as to how I can do this
and still use the .Net localization features.
My current thought is to...
1) Make a custom textbox class that has a static string value that contains
a regex pattern that each keystroke should match. The pattern to match will
be determined
by examining CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits
and CurrencyDecimalSeparator. I'm hoping the total number of regex patterns
is pretty small ( I only know of decimal and non-decimal currencies overall,
and only "." and "," as decimal separators - that only gives me four total
patterns if I don't consider fractional inputs) Plus I can always build my
regex pattern dynamically).
2) Validate the input string against the regex pattern on each keystroke.
"handle" any keystrokes that break the regex.
Any help is appreciated.
BBM