Link to home
Start Free TrialLog in
Avatar of deanlee17
deanlee17

asked on

Textbox check

Hi guys,

I would like to check that a textbox contains no characters and can only be (for example)...

1
1.00
100,000.00
etc

Thanks,
Dean.
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Avatar of deanlee17
deanlee17

ASKER

I shud maybe mention, this is a WPF application.
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
One solution would be to capture the onKeyUp event. When a user enters a character in the textbox you can use this event to ensure he has only entered a valid character (in this case numeric only)
Hi.

1. On the KeyPress event, set e.handle to true if the character is not a digit, dot (.) or backspace.

2. on validate event you have several options:
    a. perform a Double.TryParse on the textbox's content and set e.cancel to true if it fails.
    you can check for range validity as well.
   b. Use regular expression to check it.

Good luck.