Capture and Identify User Input

  • Thread starter Thread starter Dennis
  • Start date Start date
D

Dennis

If a Window's form contains two textboxes, txtUserName for names and the
other txtDimension for mathematical values, how could the program code
be set up to identify that only letter character(s) are entered into
txtUserName .... and that only numbers and decimals are entered into
txtDimension ?

Secondly, how could the program code be set up to inform the user that the
wrong type of data was entered ?

All constructive suggestions are welcome.

Dennis
 
Dennis said:
If a Window's form contains two textboxes, txtUserName for names and
the other txtDimension for mathematical values, how could the program
code be set up to identify that only letter character(s) are entered into
txtUserName .... and that only numbers and decimals are entered into
txtDimension ?

The System.Text.RegularExpressions.Regex class will handle this quite
nicely:

Regex.IsMatch(<someString>, "([a-zA-Z]+)") will return false if the
supplied string does not consist solely of alphabetic characters.

Regex.IsMatch(<string>, "([0-9]+).") will return false if the supplied
string does not consist solely of numeric characters with an optional
decimal.
Secondly, how could the program code be set up to inform the user
that the wrong type of data was entered ?

You can either perform the checking when they press an OK or Submit
button or you can handle the TextChanged event and perform the checking
as the user enters the values. In either case, just throw up a MessagBox
alerting then to the problem.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
Back
Top