integer validation

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

    integer validation

    How do I validate an integer number using asp.net with c#?

    Eugene Anthony

    *** Sent via Developersdex http://www.developersdex.com ***
  • Eliyahu Goldin

    #2
    Re: integer validation

    You can:

    1) call Int32.Parse method and catch exceptions
    2) call Int32.TryParse method and check the return value
    3) don't validate anything, just go ahead. You will get an exception if
    something is wrong.

    3) is the common choice in most of scenarios.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]




    "Eugene Anthony" <solomon_13000@ yahoo.comwrote in message
    news:OE8nXM1fHH A.4980@TK2MSFTN GP02.phx.gbl...
    How do I validate an integer number using asp.net with c#?
    >
    Eugene Anthony
    >
    *** Sent via Developersdex http://www.developersdex.com ***

    Comment

    • Rad [Visual C# MVP]

      #3
      Re: integer validation

      On Sun, 15 Apr 2007 14:54:48 +0300, Eliyahu Goldin wrote:
      You can:
      >
      1) call Int32.Parse method and catch exceptions
      2) call Int32.TryParse method and check the return value
      3) don't validate anything, just go ahead. You will get an exception if
      something is wrong.
      >
      3) is the common choice in most of scenarios.
      Or better yet you could use a ASP.NET data type check validator
      --
      Bits.Bytes

      Comment

      • Eliyahu Goldin

        #4
        Re: integer validation

        Some developers consider validators cumbersome and don't use them.

        --
        Eliyahu Goldin,
        Software Developer & Consultant
        Microsoft MVP [ASP.NET]




        "Rad [Visual C# MVP]" <nospam@nospam. comwrote in message
        news:m4aualaa9b ri.dlg@thinkers room.com...
        On Sun, 15 Apr 2007 14:54:48 +0300, Eliyahu Goldin wrote:
        >
        >You can:
        >>
        >1) call Int32.Parse method and catch exceptions
        >2) call Int32.TryParse method and check the return value
        >3) don't validate anything, just go ahead. You will get an exception if
        >something is wrong.
        >>
        >3) is the common choice in most of scenarios.
        >
        Or better yet you could use a ASP.NET data type check validator
        --
        Bits.Bytes
        http://bytes.thinkersroom.com

        Comment

        • Mark Rae

          #5
          Re: integer validation

          "Eliyahu Goldin" <REMOVEALLCAPIT ALSeEgGoldDinN@ mMvVpPsS.orgwro te in
          message news:uYLEDu2fHH A.1008@TK2MSFTN GP05.phx.gbl...
          Some developers consider validators cumbersome and don't use them.
          I certainly never use them - my library of client-side JavaScript validation
          routines is many times more flexible...


          Comment

          • Rad [Visual C# MVP]

            #6
            Re: integer validation

            On Sun, 15 Apr 2007 17:36:51 +0300, Eliyahu Goldin wrote:
            Some developers consider validators cumbersome and don't use them.
            Hmm ... Cumbersome? How so? Personally I find them to be pretty handy. Drag
            onto the page, set a few properties and you're good to go. Though one
            should do sever side validation anyway just in case javascript has been
            disabled on the client
            --
            Bits.Bytes

            Comment

            • sloan

              #7
              Re: integer validation


              Mark

              Looks like another "rapid vs good" kind of debate.


              The custom validators are good for rapid development.

              But I (as it seems Mark) has done, is created some custom and reusable java
              scripts routines.

              The biz layer should check and catch for all errors. The use of JavaScript
              should only be used to avoid a round trip to the server.
              Why?

              What if you want to code up a winforms presentation layer? You'd have to
              re-code up all those checks if you didn't put them properly in the biz
              layer.
              Aka, now 2 places to upkeep and maintain. And one of them (javascript)
              isn't even guaranteed to work.

              Do your checks in the biz layer. Create some custom exceptions.
              Use javascript as a helper to avoid a round trip.

              You'll also notice that the custom validators are only the most trivial
              things.

              When you start working with forms with complicated rules beyond stuff like
              "yes / no" or some text in a textbox, then having some better than the
              custom validators makes your code better and more maintainable.

              I'm sure others will disagree. I've worked with some of you in the past and
              present.

              ...


              "Mark Rae" <mark@markNOSPA Mrae.netwrote in message
              news:uhHbkO3fHH A.3676@TK2MSFTN GP05.phx.gbl...
              "Eliyahu Goldin" <REMOVEALLCAPIT ALSeEgGoldDinN@ mMvVpPsS.orgwro te in
              message news:uYLEDu2fHH A.1008@TK2MSFTN GP05.phx.gbl...
              >
              Some developers consider validators cumbersome and don't use them.
              >
              I certainly never use them - my library of client-side JavaScript
              validation
              routines is many times more flexible...
              >
              >

              Comment

              • Mark Rae

                #8
                Re: integer validation

                "sloan" <sloan@ipass.ne twrote in message
                news:eItTAr3fHH A.3676@TK2MSFTN GP05.phx.gbl...
                Looks like another "rapid vs good" kind of debate.
                Yes indeed.
                The custom validators are good for rapid development.
                Only if you never intend to do anything even slightly complex with them...
                But I (as it seems Mark) has done, is created some custom and reusable
                java
                scripts routines.
                Indeed. In fact, armed with a comprehensive JavaScript validation library,
                it is in fact much easier (and therefore quicker) *not* to use the custom
                validators!

                Same argument for the new SqlDataSource / ObjectDataSourc e stuff - if you
                have a decent DAL, it's much easier not to use them...
                You'll also notice that the custom validators are only the most trivial
                things.
                That is my main reason for not using them...
                When you start working with forms with complicated rules beyond stuff like
                "yes / no" or some text in a textbox, then having some better than the
                custom validators makes your code better and more maintainable.
                I couldn't agree more.


                Comment

                Working...