Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. What´s the best way for validating input data?

What´s the best way for validating input data?

Scheduled Pinned Locked Moved C#
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    markdbd
    wrote on last edited by
    #1

    I validate all input data using a Validation class with functions like: IsAlpha, IsAlphaNumeric, IsEmail, Lenght, IsNumber Normally I make the validation in the Click Event of a form, and then I show the errors using an error control. Is there a better way to validate input data? And for what are the events "Validated" and "Validating"? Thanks.

    S 1 Reply Last reply
    0
    • M markdbd

      I validate all input data using a Validation class with functions like: IsAlpha, IsAlphaNumeric, IsEmail, Lenght, IsNumber Normally I make the validation in the Click Event of a form, and then I show the errors using an error control. Is there a better way to validate input data? And for what are the events "Validated" and "Validating"? Thanks.

      S Offline
      S Offline
      sreejith ss nair
      wrote on last edited by
      #2

      hi, If you are talking about windows application then you have to write custom functions like what you mentioned. And you can provide ErrorProvider control for interactive error notification. You can encapsulate your custom error checking here in Validated event of your textbox controls. eg. private void TextBox1_Validated(object sender, System.EventArgs e) { if(IsValid()) { nameErrorProvider.SetError(this.TextBox1, ""); } else { // Set the error if the name is not valid. nameErrorProvider.SetError(this.TextBox1, "Name is required."); } } ;) ************************** S r e e j i t h N a i r **************************

      M 1 Reply Last reply
      0
      • S sreejith ss nair

        hi, If you are talking about windows application then you have to write custom functions like what you mentioned. And you can provide ErrorProvider control for interactive error notification. You can encapsulate your custom error checking here in Validated event of your textbox controls. eg. private void TextBox1_Validated(object sender, System.EventArgs e) { if(IsValid()) { nameErrorProvider.SetError(this.TextBox1, ""); } else { // Set the error if the name is not valid. nameErrorProvider.SetError(this.TextBox1, "Name is required."); } } ;) ************************** S r e e j i t h N a i r **************************

        M Offline
        M Offline
        markdbd
        wrote on last edited by
        #3

        Thanks for the answer sreejith ss nair. I also found good info at MSDN about Validating. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclassvalidatedtopic.asp[^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups