locked
How can i restrict certain words in a textbox ? RRS feed

  • Question

  • User1253338400 posted

    Hi ,

    I have the following 

    private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
    {
    if (!char.IsLetter(e.KeyChar) && (!char.IsControl(e.KeyChar)) && (!char.IsWhiteSpace(e.KeyChar)))
    {
            e.Handled = true;
    }
    }

    but how can i restrict the input to be only  certain words not all letters. So for example restrict only the words Admin or  User to be entered  ?

    Tuesday, April 28, 2020 12:02 AM

Answers

  • User303363814 posted

    Use a drop-down list (select box) to limit the options.

    Alternatively, radio buttons allow users to select one item from a set of options.

    A text box is the wrong input widget to use.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 28, 2020 2:38 AM

All replies

  • User303363814 posted

    Use a drop-down list (select box) to limit the options.

    Alternatively, radio buttons allow users to select one item from a set of options.

    A text box is the wrong input widget to use.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 28, 2020 2:38 AM
  • User1253338400 posted

    i have used the drop-down list as suggested.

    thanks

    Tuesday, April 28, 2020 2:48 AM