473,503 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does anyone know how to do a Regex for the following scenario's?

I have a textbox that displays money amounts as 999999999.99. The user would
like the keyer to either type in a decimal point or, if one is NOT supplied,
imply one. Furthermore, when the textbox is populated from the database
using a money datatype, it is four decimals to the right, which must be
formatted to two.

So, as far as keying, if a user (as an extreme) types in the following, they
should diplay as:

1 display as 0.01

..1 display as 1.10

100 display as 1.00

1.00 display as 1.00

1.0000 display as 1.00

etc.

I'm sure this can be done using Regex, but it seems a little tricky.
Nov 15 '05 #1
1 1307
why in the world would you use Regex for this?

a little bit of logic in the KeyPress event should be all you need to
interpret the keys correctly.

Why not create your own control, derived from the textbox control, that will
handle this for you. Add a 'Value' field to the list of properties...

a) when the 'Value' field is assigned, make sure it is a number, and simply
format the to the correct number of decimal points. Lookup from database is
now taken care of.
b) when Value is assigned a 0, display 0.00 in the empty field. When you
create a new record, you now have a way to initialize the display.
c) When the user gets to the field, you take control of the KeyPress
functionality. With every keypress, you display the correct visible
representation.

display then user presses
0.00 1
0.01 0
0.10 4
1.04 3
10.43 decimal
1043.00 4
1043.40 6
1043.46 7
no change 6
no change

Now, when your code asks for the value of the field: you return 1043.46 as a
currency value.

That shouldn't be too hard to write.

--- Nick
"Top Gun" <nf*@nospam.com> wrote in message
news:ul**************@TK2MSFTNGP12.phx.gbl...
I have a textbox that displays money amounts as 999999999.99. The user would like the keyer to either type in a decimal point or, if one is NOT supplied, imply one. Furthermore, when the textbox is populated from the database
using a money datatype, it is four decimals to the right, which must be
formatted to two.

So, as far as keying, if a user (as an extreme) types in the following, they should diplay as:

1 display as 0.01

.1 display as 1.10

100 display as 1.00

1.00 display as 1.00

1.0000 display as 1.00

etc.

I'm sure this can be done using Regex, but it seems a little tricky.

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3393
by: Dean H. Saxe | last post by:
I'm currently developing a tool in perl to search out potential XSS (Cross Site Scripting) vulnerabilities and correct them in a ColdFusion based web app. I've been having great success so far,...
5
2383
by: ¶©¼z | last post by:
hello, everybody i would like to know how to split a string which composed of (characters,digits) E.g. the string is ABC001, i would like split the "ABC" char and digits +1 to 002 then combine...
5
5076
by: Chris | last post by:
How Do I use the following auto-generated code from The Regulator? '------------------------------------------------------------------------------ ' <autogenerated> ' This code was generated...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.