Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6122141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:51:51+00:00 2026-05-23T15:51:51+00:00

the question was accepting one or many ports that has one space between them

  • 0

the question was accepting one or many ports that has one space between them

with help of friends
here, I used this one for my answer
but for example if I enter 88888 it will alert me such this thing:

88888NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN is not correct

how can I correct this

<script type="text/javascript">
    function portvalidating(field)
    {
    var output='';
        m=field.value;
        if(/^\d{1,5}([ ]\d{1,5})*$/.test(m))
        {
        var parts = m.split(' ');
        for(i in parts)
        {
          var p= parseInt(parts[i]);
        if(!((0 <= p) && (p<= 65535) && !isNaN(p)))
        {
        output+=p;
        }
        }
    if(output=='')
        var dummy=1;
        else alert(output+'is not correct');
        }
        else alert('please enter a valid port!');
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:51:52+00:00Added an answer on May 23, 2026 at 3:51 pm

    Try separating your concerns of reading/writing to form data from input validation from alerting. Here is a hint on the function to validate a string of space separated integers in [0..65535]:

    var getPorts = function(str) {
      var ns=(""+str).split(/\s+/), ports=[], n, i;
      for (i=0; i<ns.length; i++) {
        n = parseInt(ns[i], 10);
        if (isFinite(n) && !isNaN(n)
              && (ns[i]==n) // Make sure the number is an integer.
              && (n >= 0) && (n <= 65535)) {
          ports.push(n);
        }
      }
      return ports;
    };
    
    getPorts('-1 0 NaN 123 foo 255 99999'); // => [0, 123, 255]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question has been asked a lot of times in many forums. But I
This relates to my other question on accessing a REST service that uses forms
Question Can I build a image database/library that has an e-commerce style checkout system
Long-delayed update I'm accepting MUG4N's answer to this question, and I also want to
I've read many threads on here and haven't yet come across the right one.
My question is similar to this one and I am having a similar issue,
I have a Question (q) with many Answers, each Answer has a variety of
This question is related to a previous one on writing a session timeout handler
QUESTION: How can I handle potential contention between two separate threads accessing the same
I'm relatively new to utilizing web services. I'm trying to create one that will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.