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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:06:28+00:00 2026-05-19T09:06:28+00:00

There are two URLs I have: http://localhost:65043/home/create/ http://localhost:65043/home/create/2 I want to check that the

  • 0

There are two URLs I have:

http://localhost:65043/home/create/

http://localhost:65043/home/create/2

I want to check that the ID exists in the URL or not. If yes, then I need to parse them, otherwise I got 0.

How I can get the ID from the URL and if they not, have that get 0 from that and return a thing that shows that “It is new. No ID exists with URL”

How I can do this?

  • 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-19T09:06:29+00:00Added an answer on May 19, 2026 at 9:06 am
     // Grab the complete URL
     var loc = document.location.href;
    
     // Strip the things we don't need
     loc = loc.replace('http://localhost:65043/home/create/','')
    
     // Make the remnants a number 
     var id = parseInt(loc, 10);
    
     // Test if the remnants are a number or assign 0
     id = isNaN(id) ? 0 : id;
    

    If you want to do it all at once in a silly way, you can reverse the URL and put it into a parseInt. Then test if it is a number. So you don’t need to know where the URL is running, only to check if the last part of the path is an ID.

    var id = parseInt(parseInt(
        document.location.href
        .split('')
        .reverse()
        .join(''), 10) 
          .toString()
          .split('')
          .reverse()
          .join(''), 10) | 0;
    

    But as you can see, that gets quite unreadable. (And is about four times slower.)

    It basically:

    • Reverses the URL
    • Puts it in parseInt (since that tries to parse an int from left to right it seems quite fitting then)
    • Then I have to reverse the number (as a string) again otherwise it was backwards, and parse it again as int
    • Do an OR operation with 0 that will return 0 if all previous operations resulted in not a number.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two URLs with parameters http://localhost:8041/Reforge.aspx?name=CyanГ http://localhost:8041/Reforge.aspx?name=Cyanì In first URL Firefox encodes last
There is a page on our server that's reachable via two different URLs. http://www.spotlight.com/6213-5613-0721
I have Urls like the one below in my blog. http://www.domain.com/live/comments/the_winter_is_set_to_end_the_same_way_it_began_on_a_very_mild_note/ There is two
This script works well unless you put two URLS in that do not have
i have many urls(string): $one = 'http://www.site.com/first/1/two/2/three/3/number/342'; $two = '/first/1/two/2/number/32'; $three = 'site.com/first/1/three/3/number/7'; $four
I have these two URL's I want to make available to my users: /Account/Orders
I have read a document that they say: In java there two types of
I have a website that has images with urls like this: http://mysite.com/image1.jpg My server
I have a list of dicts that stores URLs. It has simply two fields,
When I clone a repository, is there any difference between these two URLs? Without

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.