javascript validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krishvasu
    New Member
    • Apr 2010
    • 9

    #1

    javascript validation

    how to validate numeric + alpha in javascript..... ..,

    EX:

    Emp Id:

    1. Ab1212
    2. asdfgd
    3. 123445

    how to validate this type of numbers........ ....,
    only six numbers wil be accept........,
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    exactly 6 or 6 at max? ... probably the best way would be a regExp, but there are a lot of possibilities to achieve that task ... you could even loop through the characters of the string for example etc. ...

    kind regards

    Comment

    • krishvasu
      New Member
      • Apr 2010
      • 9

      #3
      how to validate this type of numbers

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        ??? here is an example to test a string s for containing exactly 6 numbers ... you would just need to adapt that to your needs ... since you didn't clearly specify your requirement:

        Code:
        var s = '13245a';
        
        function validate(s) {
            var re = /\d{6,6}/;
        
            return re.test(s);
        }
        
        alert(validate(s));
        regards

        Comment

        • krishvasu
          New Member
          • Apr 2010
          • 9

          #5
          javacript validation

          how to validate numeric numbers........ ,
          Attached Files

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            threads merged - don't split one issue in different threads!

            regards
            MOD

            Comment

            • gits
              Recognized Expert Moderator Expert
              • May 2007
              • 5390

              #7
              to your following code:
              Code:
              <html>
              <head>
              <script type="text/javascript">
              var s = '12345a';
              function validate(s)
              {
              var re = /\d{6,6}/;
              return re.test(s);
              }
              alert(validate(s));
              </script>
              </head>
              <body>
              <form action=" " onsubmit="return validate()">
              <table>
              <tr><td>emp id</td><td><input type="text" id=" "></td></tr>
              <tr><td><input type="submit" value="submit"></td></tr>
              </table>
              </form>
              </body>
              you just copied and pasted the above example to a html-page. you need to adapt that, so that the value of the input node is retrieved and validated ... currently you call the validate() method without an argument. you should even drop the alert and the variable declaration for s.

              regards

              Comment

              Working...