/^\d+$/ - please explain what does it mean

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ravigpalli
    New Member
    • May 2017
    • 6

    /^\d+$/ - please explain what does it mean

    Hi All,

    Can some one please explain what exactly is the below line in bold means ,

    Code:
    var i = ctl.id;
    var j =g_form.getValue(i);
    
    var port = j;
    if (/^\d+$/.test(port)){ ----- Please explain what is this
      var k =parseInt(g_form.getValue(i));
      if (k<1 || k>65000){
      alert('Invalid Port Number: Value must be <= 65000');
      g_form.clearValue(i);
      }
    }
    
    else{
      var ports = port.split("-");
      if ((/^\d+$/.test(ports[0])) && (/^\d+$/.test(ports[1])) && (ports[0] < ports[1]) && ports[0] <=65000 && ports[1] <=65000 ){}
      else{
      alert("Invalid Port Range: Please enter numeric value") ;
      g_form.clearValue(i);
      }
      }
    My Requirement is , port column in catalog table is just accepting numbers and numbers with - .

    Now we need to have the below , please let me know how to get this done.
    - An open-ended range of ports with Less Than or Greater than: >1023
    - A combination of the above formats separated by commas: 21, 80-81, >1023
    - Negate a single number: !80
    Last edited by Dormilich; May 29 '17, 02:16 PM. Reason: please use code tags.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    there is no line in bold ...

    Comment

    • ravigpalli
      New Member
      • May 2017
      • 6

      #3
      Hi ,
      Please see the lines below , what I was referring to .
      if (/^\d+$/.test(port))
      and
      if ((/^\d+$/.test(ports[0])) && (/^\d+$/.test(ports[1])) && (ports[0] < ports[1]) && ports[0] <=65000 && ports[1] <=65000 ){}
      else{
      alert("Invalid Port Range: Please enter numeric value") ;
      g_form.clearVal ue(i);
      }
      }

      Please let me know what can I do to include 3 ranges I mentioned above.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        /^\d+$/ simply means: only digits.

        Comment

        • ravigpalli
          New Member
          • May 2017
          • 6

          #5
          Ok , Please let me know what I need to do for including below .

          - An open-ended range of ports with Less Than or Greater than: >1023
          - A combination of the above formats separated by commas: 21, 80-81, >1023
          - Negate a single number: !80

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            An open-ended range of ports with Less Than or Greater than: >1023
            Negate a single number: !80
            make a separate test for that

            A combination of the above formats separated by commas: 21, 80-81, >1023
            explode by ,, trim, and do validation for each item.

            Comment

            • ravigpalli
              New Member
              • May 2017
              • 6

              #7
              Sorry ,

              I did not understand what you are trying to say .
              An open-ended range of ports with Less Than or Greater than: >1023
              Negate a single number: !80
              make a separate test for that - How to test this.

              A combination of the above formats separated by commas: 21, 80-81, >1023
              explode by ,, trim, and do validation for each item. - Please explain how to do this.

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                make a separate test for that - How to test this.
                well, I expect you to be able to write an if() condition that tests if a number is not 80 ...


                explode by ,, trim, and do validation for each item.
                explode: https://developer.mozilla.org/en-US/...s/String/split
                trim: https://developer.mozilla.org/de/doc...ts/String/Trim
                for each: https://developer.mozilla.org/en-US/.../Array/forEach

                Comment

                • ravigpalli
                  New Member
                  • May 2017
                  • 6

                  #9
                  Hi,

                  Please let me know how to achieve this
                  An open-ended range of ports with Less Than or Greater than: >1023.

                  Also , I am new to java script , can you please help

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    that requirement is the same as "not 1023".

                    Comment

                    • ravigpalli
                      New Member
                      • May 2017
                      • 6

                      #11
                      Actually we need to have > and < sysmbols included. ANy idea.

                      Comment

                      • Dormilich
                        Recognized Expert Expert
                        • Aug 2008
                        • 8694

                        #12
                        it makes no sense to include > and < when it's not necessary.

                        Comment

                        Working...