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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How To Validating Float,Date,Time in C#?

How To Validating Float,Date,Time in C#?

Scheduled Pinned Locked Moved C#
helpcsharptutorialquestion
10 Posts 5 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.
  • C Offline
    C Offline
    Coding C
    wrote on last edited by
    #1

    Hi gurus, I am facing a problem while validating float,date,time values in string variables in c#. Can Anybody tell me the way to validate the values. plz help. thanks in advance.:) Nitin...

    S C 2 Replies Last reply
    0
    • C Coding C

      Hi gurus, I am facing a problem while validating float,date,time values in string variables in c#. Can Anybody tell me the way to validate the values. plz help. thanks in advance.:) Nitin...

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      Use Double.TryParse or DateTime.TryParse.


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      C 1 Reply Last reply
      0
      • S Stefan Troschuetz

        Use Double.TryParse or DateTime.TryParse.


        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

        www.troschuetz.de

        C Offline
        C Offline
        Coding C
        wrote on last edited by
        #3

        hi, i checked the way you suggested, it worked with double.tryparse but there is no such option like datetime.tryparse. please check this out. thanks. Nitin.

        S 1 Reply Last reply
        0
        • C Coding C

          Hi gurus, I am facing a problem while validating float,date,time values in string variables in c#. Can Anybody tell me the way to validate the values. plz help. thanks in advance.:) Nitin...

          C Offline
          C Offline
          coolestCoder
          wrote on last edited by
          #4

          Hi, Use the try catch block ! try { DateTime.Parse(textBox1.Text) // code if it is date ! } catch(Exception ex) { //error code }


          "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


          Anant Y. Kulkarni

          C 1 Reply Last reply
          0
          • C coolestCoder

            Hi, Use the try catch block ! try { DateTime.Parse(textBox1.Text) // code if it is date ! } catch(Exception ex) { //error code }


            "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


            Anant Y. Kulkarni

            C Offline
            C Offline
            Coding C
            wrote on last edited by
            #5

            Thanks Nitin...

            1 Reply Last reply
            0
            • C Coding C

              hi, i checked the way you suggested, it worked with double.tryparse but there is no such option like datetime.tryparse. please check this out. thanks. Nitin.

              S Offline
              S Offline
              Stefan Troschuetz
              wrote on last edited by
              #6

              There is a DateTime.TryParse method! It's new with the Framework 2.0 but as you found double.TryParse you're clearly using this version. Maybe you misspelled.


              "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

              www.troschuetz.de

              C 1 Reply Last reply
              0
              • S Stefan Troschuetz

                There is a DateTime.TryParse method! It's new with the Framework 2.0 but as you found double.TryParse you're clearly using this version. Maybe you misspelled.


                "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

                www.troschuetz.de

                C Offline
                C Offline
                Coding C
                wrote on last edited by
                #7

                Hi, thanks for your reply but sorry to say i cant find DateTime.TryParse. :(

                R 1 Reply Last reply
                0
                • C Coding C

                  Hi, thanks for your reply but sorry to say i cant find DateTime.TryParse. :(

                  R Offline
                  R Offline
                  Robert Rohde
                  wrote on last edited by
                  #8

                  Here[^] it is.

                  C 1 Reply Last reply
                  0
                  • R Robert Rohde

                    Here[^] it is.

                    C Offline
                    C Offline
                    Coding C
                    wrote on last edited by
                    #9

                    hi, thanks for the link. it suggest that DateTime.TryParse exits. but dont know which version of .net m using i cant find DateTime.TryParse. i ll hv to check the version. thanks:)

                    L 1 Reply Last reply
                    0
                    • C Coding C

                      hi, thanks for the link. it suggest that DateTime.TryParse exits. but dont know which version of .net m using i cant find DateTime.TryParse. i ll hv to check the version. thanks:)

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      You don't know which .NET version you are using? Huh? Well if you can't use it, then you have .NET 1.1, otherwise .NET 2.0. But you can also use DateTime.Parse() and catch the exception regards

                      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