Capture and Identify User Input

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennis

    #1

    Capture and Identify User Input

    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


  • Frank Oquendo

    #2
    Re: Capture and Identify User Input

    Dennis wrote:[color=blue]
    > 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[/color]
    into[color=blue]
    > txtUserName .... and that only numbers and decimals are entered into
    > txtDimension ?[/color]

    The System.Text.Reg ularExpressions .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.
    [color=blue]
    > Secondly, how could the program code be set up to inform the user
    > that the wrong type of data was entered ?[/color]

    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.


    (Pull the pin to reply)


    Comment

    Working...