TextBox Validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eihabisaac
    New Member
    • Aug 2007
    • 38

    TextBox Validation

    Hi,

    i'm working with c# and MySQL, and i need to validate some textboxes to ensure valid data is inserted to the database.

    i did some coding and it works but i need the easiest and the right way to do that and if there is a TOOLBOX for validation that will be great.

    Code:
    private void textBox1_Validating(object sender, CancelEventArgs e)
    {
    if (String.IsNullOrEmpty(textBox1.Text))
    e.Cancel = true;
    }
    not just for null value, i need to make sure only numbers are inserted.

    thanks in advance for any help
    Last edited by tlhintoq; Mar 31 '09, 02:24 PM. Reason: [CODE] tags added
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Option A: Change the Textbox for a NumericUpDown

    Option B: Create a custom Textbox, inheriting from Textbox that filters on the Keypress event and only allows numbers to be entered.

    Option C: Parse your text in a loop character by character to make sure each one is a number.

    Option D: Regular Expressions (RegEx)

    Comment

    • orked
      New Member
      • Jan 2009
      • 49

      #3
      you can make validation on text box from toolbox ,choose validation if you want write number only choose regular expression validator and write in its properties
      (validation expression)this expression(\d{n umbers of numbers you want to enter it })
      if you refuse null value this expression make what you want.
      Good luck.

      Comment

      Working...