Click here to Skip to main content
15,890,399 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

At character keypress, how do you code so the following....

1. Only allow numeric and "-"
2. Only allow 2 decimal places
3. Only allow 4 numbers after the decimal point.

Thanks in advance.
Posted
Comments
Richard Deeming 14-Oct-15 12:20pm    
"2 decimal places"
"4 numbers after the decimal point"

Which is it? You can't have both 2 and 4 decimal places at the same time!

You'll also need to specify which UI framework you're using - Windows Forms, WPF, Universal App, Xamarin, ASP.NET WebForms, ASP.NET MVC, or something else?
Maciej Los 14-Oct-15 12:25pm    
Not a question at all! Please, provide more details about you have trying to achieve till now and where are you stuck?
Central_IT 15-Oct-15 14:34pm    
example....
1234.65 is okay
but will not allow 12345.65.

 
Share this answer
 
v2
Not even a question and so little information that one have to guess what you want.
And the question look like a "DoMyWork" which not what we do, it is the wrong place.

Quote:
At character keypress

this let me think that you want to do some formatted input.
There is basically 2 possibilities:
- you do normal input and then you check the input when validated.
- you monitor every event in the textbox, keys presses and cursor moves, and a program of you controls what is done as events are processed.

Unfortunately, this depend on the framework you are using.

I have been doing this for 30 years now, it is a standard feature with xBase family languages (FoxPro, Clipper ...)

I suggest to Google for formatted input for more informations.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900