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. JavaScript
  4. user should have to enter 4 numbers in textbox after 4 numbers textbox should not take any number

user should have to enter 4 numbers in textbox after 4 numbers textbox should not take any number

Scheduled Pinned Locked Moved JavaScript
15 Posts 4 Posters 1 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.
  • Y Offline
    Y Offline
    yogesh89
    wrote on last edited by
    #1

    i have a form in which i am entering country code and zip code. user should have to enter 4 numbers in country textbox after 4 numbers country textbox should not take any number. please reply..........

    R N L 3 Replies Last reply
    0
    • Y yogesh89

      i have a form in which i am entering country code and zip code. user should have to enter 4 numbers in country textbox after 4 numbers country textbox should not take any number. please reply..........

      R Offline
      R Offline
      Roman_wolf
      wrote on last edited by
      #2

      The TextBox has a "MaxLength" attribute. It does exactly what you want.

      N 1 Reply Last reply
      0
      • Y yogesh89

        i have a form in which i am entering country code and zip code. user should have to enter 4 numbers in country textbox after 4 numbers country textbox should not take any number. please reply..........

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        Using a masked edit texbox you can restrict the input to a specific lenght and type. Search for the term and you will find many examples from custom server controls to JavaScript solutions. Pick one that will work for you.


        I know the language. I've read a book. - _Madmatt

        1 Reply Last reply
        0
        • R Roman_wolf

          The TextBox has a "MaxLength" attribute. It does exactly what you want.

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          That won't quite do it. The OP said NUMBERS. Your solutions will only limit the length but still allow any character to be entered.


          I know the language. I've read a book. - _Madmatt

          R 1 Reply Last reply
          0
          • N Not Active

            That won't quite do it. The OP said NUMBERS. Your solutions will only limit the length but still allow any character to be entered.


            I know the language. I've read a book. - _Madmatt

            R Offline
            R Offline
            Roman_wolf
            wrote on last edited by
            #5

            Ok then, I missed the "numbers" part of the question. But then this can easily be taken into account by adding a compare validator that checks for the type.

            N 1 Reply Last reply
            0
            • R Roman_wolf

              Ok then, I missed the "numbers" part of the question. But then this can easily be taken into account by adding a compare validator that checks for the type.

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #6

              No, a compare validator works by comparing the value of one field to another. It, or any validator, also does not prevent characters from being entered when only numbers are expected. Validators check the input afterward, they don't prevent entry.


              I know the language. I've read a book. - _Madmatt

              R 1 Reply Last reply
              0
              • Y yogesh89

                i have a form in which i am entering country code and zip code. user should have to enter 4 numbers in country textbox after 4 numbers country textbox should not take any number. please reply..........

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

                You can use the MaxLength attribute of the textbox to limit the lengh to 4 and use this function to limit the input to only numbers. If you want to restrict entry of invalid characters, you'll have to handle the keypress event and write appropriate code.

                function isNumeric(str)
                {
                var i=0;
                for(i=0;i '9')
                return false;
                }
                return true;
                }

                N 1 Reply Last reply
                0
                • L Lost User

                  You can use the MaxLength attribute of the textbox to limit the lengh to 4 and use this function to limit the input to only numbers. If you want to restrict entry of invalid characters, you'll have to handle the keypress event and write appropriate code.

                  function isNumeric(str)
                  {
                  var i=0;
                  for(i=0;i '9')
                  return false;
                  }
                  return true;
                  }

                  N Offline
                  N Offline
                  Not Active
                  wrote on last edited by
                  #8

                  There are far better examples and implementations than this.


                  I know the language. I've read a book. - _Madmatt

                  L 1 Reply Last reply
                  0
                  • N Not Active

                    There are far better examples and implementations than this.


                    I know the language. I've read a book. - _Madmatt

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

                    I understand, but for a starter, this should be okay. Moreover, by redirecting new users to pre-written frameworks and controls, we're actually discouraging them from learning the language itself.

                    N 1 Reply Last reply
                    0
                    • N Not Active

                      No, a compare validator works by comparing the value of one field to another. It, or any validator, also does not prevent characters from being entered when only numbers are expected. Validators check the input afterward, they don't prevent entry.


                      I know the language. I've read a book. - _Madmatt

                      R Offline
                      R Offline
                      Roman_wolf
                      wrote on last edited by
                      #10

                      Ok I agree on the second part. However, a compare validator can be used to check for data types

                      N 1 Reply Last reply
                      0
                      • L Lost User

                        I understand, but for a starter, this should be okay. Moreover, by redirecting new users to pre-written frameworks and controls, we're actually discouraging them from learning the language itself.

                        N Offline
                        N Offline
                        Not Active
                        wrote on last edited by
                        #11

                        Shameel wrote:

                        we're actually discouraging them from learning the language itself.

                        No. .NET is a pre-written framework, has it discouraged you from learning? JQuery is a framework, have you stopped learning JavaScript? Lazy coders may not want to learn any further than how to use an API but true developers will learn and better themselves. Expereinced developers also know to not recreate the wheel, if there is a perfectly good framework or control to do what is needed they will use it and save the time for more complex problems.


                        I know the language. I've read a book. - _Madmatt

                        L 1 Reply Last reply
                        0
                        • R Roman_wolf

                          Ok I agree on the second part. However, a compare validator can be used to check for data types

                          N Offline
                          N Offline
                          Not Active
                          wrote on last edited by
                          #12

                          Once again, this is after the fact. It does not prevent entry. Thanks for playing.


                          I know the language. I've read a book. - _Madmatt

                          R 1 Reply Last reply
                          0
                          • N Not Active

                            Once again, this is after the fact. It does not prevent entry. Thanks for playing.


                            I know the language. I've read a book. - _Madmatt

                            R Offline
                            R Offline
                            Roman_wolf
                            wrote on last edited by
                            #13

                            In which I said that you were right. What I was replying to was the first part of your statement "No, a compare validator works by comparing the value of one field to another"

                            1 Reply Last reply
                            0
                            • N Not Active

                              Shameel wrote:

                              we're actually discouraging them from learning the language itself.

                              No. .NET is a pre-written framework, has it discouraged you from learning? JQuery is a framework, have you stopped learning JavaScript? Lazy coders may not want to learn any further than how to use an API but true developers will learn and better themselves. Expereinced developers also know to not recreate the wheel, if there is a perfectly good framework or control to do what is needed they will use it and save the time for more complex problems.


                              I know the language. I've read a book. - _Madmatt

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

                              Mark Nischalke wrote:

                              Expereinced developers also know to not recreate the wheel, if there is a perfectly good framework or control to do what is needed they will use it and save the time for more complex problems.

                              Correct. But the OP doesn't seem to be an experienced guy. So, let him learn the language first.

                              N 1 Reply Last reply
                              0
                              • L Lost User

                                Mark Nischalke wrote:

                                Expereinced developers also know to not recreate the wheel, if there is a perfectly good framework or control to do what is needed they will use it and save the time for more complex problems.

                                Correct. But the OP doesn't seem to be an experienced guy. So, let him learn the language first.

                                N Offline
                                N Offline
                                Not Active
                                wrote on last edited by
                                #15

                                Inexperienced will not take the time for in-depth learning. Most employers don't pay for training or to have their devs learn something, they want results.


                                I know the language. I've read a book. - _Madmatt

                                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