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 8733355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:37:54+00:00 2026-06-13T09:37:54+00:00

I creating a web application, where I need to get a range of numbers

  • 0

I creating a web application, where I need to get a range of numbers as input:

Ex: 1-10, 0-100 etc.

The following is the code I use to get the range into variable “s” and display it. And #ucode is the ID of the textbox I use to get the input.

//JavaScript
function validate() {
    var i = $("#ucode").val(); //input
    i = i.replace(/ /,'');
    var constraint = /([0-9]+[,-])?[0-9]+$/;
    if(!constraint.test(i))
    {
        alert("Invalid Expression");
        return;
    }
    var a = i.split(","); //split and array
    var s = "";           //output string
    if(a != "")
    {
        for(n = 0; n < a.length; ++n )
        {
            var conh = /^[0-9]-[0-9]$/;
            var conc = /^[0-9]+$/;
            if(conh.test(a[n]))
            {
                var range = a[n].split("-");
                var ll = parseInt(range[0]);   //lower limit
                var ul = parseInt(range[1]);   //upper limit
                if(ul < ll) { alert("Invalid Expression"); return; }
                for(m = ll; m <= ul; ++m)
                    s += " " + m;
            }
        }
        alert(s); // Alert output
    }
}

The problem is this function works for range 1-9 not beyond that

if I give 1-9, it displays

1 2 3 4 5 6 7 8 9

if i give 1-2,5-9, it displays

1 2 5 6 7 8 9

But if I give beyond 9 i.e. 1-10 or 5-45 it shows a blank Alert Message.

Where am I wrong? Please Help Me
Thanks in advance

  • 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-06-13T09:37:56+00:00Added an answer on June 13, 2026 at 9:37 am

    First I thank @NullPointer for Idea, and @Jeff to where to use it.

    The problem was at the if() condition. So I changed the code as follows and it works fine.

    var conh = /^[0-9]+-[0-9]+$/; //Now it matches any number of digits.
    if(conh.test(a[n]))
    {
      .
      :
    }
    

    Now it works fine. Thanks friends.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a simple web application. I need to get reference to ServletContext
I am creating the Web Application, After completion of payment i need to get
I am creating a web application in Java in which I need to run
I'm creating a web application with servlets and I need a thread changing a
I am creating quite a complex web application. I like to use php to
I'm creating RSS reader application. I need to get any linked rss old items.
I am creating a web application and I want to use the Tabs widget
I am creating a Web application using ASP.NET MVC, and I'm trying to use
I am creating web application where I need to store timestamp/ date. The problem
i m creating a web application using Google map in it. i need to

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.