ASP.NET Validation. Counting number of characters in a Text Box?

Discussion in 'Digital Media' started by Basheer A, Apr 20, 2008.

  1. Basheer A Guest

    Basheer A
    Hi, Gurus,
    In my page I want to allow/restrict the user to enter minimum 2 charecters in a text box when a particular item is selected from a drop down list. How can I do it using a custom validation control.
  2. dhvrm Guest

    Just use a Regular Expression Validator.

    Toggle the validator's Enabled property to true or false based on the DropDownList's SelectedValue property. You can do that through a simple subroutine / function.

    How you define a "character" is the question.

    If you mean letters and numbers only, your ValidationExpression for the control would be: \w{2,}

    If you mean only letters, your expression would be: [a-zA-Z]{2,}

    If you mean only numbers, your expression would be: [0-9]{2,}

    If you mean anything except white space or control characters, your expression would be: \S{2,}

Share This Page