By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,529 Members | 864 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,529 IT Pros & Developers. It's quick & easy.

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

P: 6
Hi All,

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

Expand|Select|Wrap|Line Numbers
  1. var i = ctl.id;
  2. var j =g_form.getValue(i);
  3.  
  4. var port = j;
  5. if (/^\d+$/.test(port)){ ----- Please explain what is this
  6.   var k =parseInt(g_form.getValue(i));
  7.   if (k<1 || k>65000){
  8.   alert('Invalid Port Number: Value must be <= 65000');
  9.   g_form.clearValue(i);
  10.   }
  11. }
  12.  
  13. else{
  14.   var ports = port.split("-");
  15.   if ((/^\d+$/.test(ports[0])) && (/^\d+$/.test(ports[1])) && (ports[0] < ports[1]) && ports[0] <=65000 && ports[1] <=65000 ){}
  16.   else{
  17.   alert("Invalid Port Range: Please enter numeric value") ;
  18.   g_form.clearValue(i);
  19.   }
  20.   }
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
May 29 '17 #1
Share this Question
Share on Google+
11 Replies


Dormilich
Expert Mod 5K+
P: 8,639
there is no line in bold ...
May 29 '17 #2

P: 6
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.clearValue(i);
}
}

Please let me know what can I do to include 3 ranges I mentioned above.
May 29 '17 #3

Dormilich
Expert Mod 5K+
P: 8,639
/^\d+$/ simply means: only digits.
May 29 '17 #4

P: 6
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
May 29 '17 #5

Dormilich
Expert Mod 5K+
P: 8,639
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.
May 29 '17 #6

P: 6
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.
May 29 '17 #7

Dormilich
Expert Mod 5K+
P: 8,639
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
May 29 '17 #8

P: 6
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
May 29 '17 #9

Dormilich
Expert Mod 5K+
P: 8,639
that requirement is the same as "not 1023".
May 29 '17 #10

P: 6
Actually we need to have > and < sysmbols included. ANy idea.
May 29 '17 #11

Dormilich
Expert Mod 5K+
P: 8,639
it makes no sense to include > and < when it's not necessary.
May 29 '17 #12

Post your reply

Sign in to post your reply or Sign up for a free account.