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. Web Development
  3. ASP.NET
  4. Validation to accept only numbers!!!

Validation to accept only numbers!!!

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netregexquestion
6 Posts 6 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.
  • R Offline
    R Offline
    rameshbhojan
    wrote on last edited by
    #1

    Hi all, i have to validate for a textbox field in ASP.NET 2.0 using C#. the requirement is that the textfield should accept only numbers. i want the field such tat it should accept number..... any number of any length..... please send me the code for the same...... the regular expression validator with the validation expression ValidationExpression="[0-9]" accepts only a single digit number......... how do i make it accept any number!!!!!!! Thanks, Ramesh

    M N K R 4 Replies Last reply
    0
    • R rameshbhojan

      Hi all, i have to validate for a textbox field in ASP.NET 2.0 using C#. the requirement is that the textfield should accept only numbers. i want the field such tat it should accept number..... any number of any length..... please send me the code for the same...... the regular expression validator with the validation expression ValidationExpression="[0-9]" accepts only a single digit number......... how do i make it accept any number!!!!!!! Thanks, Ramesh

      M Offline
      M Offline
      Mariusz Wojcik
      wrote on last edited by
      #2

      Well, you should change the ValidationExpression to accept more than one character. Also, decide whether you will accept +/- sign before the number, decimal point etc. Than build proper regular expression and that's it. I strongly recommend to read a little about "creating regular expression" on the MSDN. And to make it works, and accept any number of digits modify ValidationExpression to "[0-9]*".

      -- Mariusz 'mAv' Wójcik master e-software engineer

      1 Reply Last reply
      0
      • R rameshbhojan

        Hi all, i have to validate for a textbox field in ASP.NET 2.0 using C#. the requirement is that the textfield should accept only numbers. i want the field such tat it should accept number..... any number of any length..... please send me the code for the same...... the regular expression validator with the validation expression ValidationExpression="[0-9]" accepts only a single digit number......... how do i make it accept any number!!!!!!! Thanks, Ramesh

        N Offline
        N Offline
        Nouman Bhatti
        wrote on last edited by
        #3

        include * in your validation expression either at the begining or at the end.

        1 Reply Last reply
        0
        • R rameshbhojan

          Hi all, i have to validate for a textbox field in ASP.NET 2.0 using C#. the requirement is that the textfield should accept only numbers. i want the field such tat it should accept number..... any number of any length..... please send me the code for the same...... the regular expression validator with the validation expression ValidationExpression="[0-9]" accepts only a single digit number......... how do i make it accept any number!!!!!!! Thanks, Ramesh

          K Offline
          K Offline
          koolprasad2003
          wrote on last edited by
          #4

          hello ramesh, try to use the following code in Javascript function CkhInte(obj) { if (isNaN(obj.value)) { alert('Please enter only digits'); return false; } } hope it helps, please rate this message if useful, best regards, koolprasad2003:)

          Be a good listener...Because Opprtunity knoughts softly...N-Joy

          D 1 Reply Last reply
          0
          • R rameshbhojan

            Hi all, i have to validate for a textbox field in ASP.NET 2.0 using C#. the requirement is that the textfield should accept only numbers. i want the field such tat it should accept number..... any number of any length..... please send me the code for the same...... the regular expression validator with the validation expression ValidationExpression="[0-9]" accepts only a single digit number......... how do i make it accept any number!!!!!!! Thanks, Ramesh

            R Offline
            R Offline
            Rahul Babu
            wrote on last edited by
            #5

            ValidationExpression="^\d+$" the above expression is a regular expression validator to validate for numbers......

            1 Reply Last reply
            0
            • K koolprasad2003

              hello ramesh, try to use the following code in Javascript function CkhInte(obj) { if (isNaN(obj.value)) { alert('Please enter only digits'); return false; } } hope it helps, please rate this message if useful, best regards, koolprasad2003:)

              Be a good listener...Because Opprtunity knoughts softly...N-Joy

              D Offline
              D Offline
              DavidNohejl
              wrote on last edited by
              #6

              Nice, but when user turn off javascript in browser it will allow him to enter incorrect input. It's necessary to do the same validation on server. ASP.NET validators do both for you.


              "Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

              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