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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:51:39+00:00 2026-05-16T08:51:39+00:00

I have an input field that saves a URL, I’d like this saved input

  • 0

I have an input field that saves a URL, I’d like this saved input to recognize when “Http//” is absent from the start of the variable but have no idea where to begin… is it possible to check only a portion of a string? – then have a function that will append if necessary?

  • 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-16T08:51:40+00:00Added an answer on May 16, 2026 at 8:51 am

    A simple solution for what you want is the following:

    var prefix = 'http://';
    if (s.substr(0, prefix.length) !== prefix)
    {
        s = prefix + s;
    }
    

    However there are a few things you should be aware of…

    The test here is case-sensitive. This means that if the string is initially Http://example.com this will change it to http://Http://example.com which is probably not what you want. You probably should also not modify any string starting with foo:// otherwise you could end up with something like http://https://example.com.

    On the other hand if you receive an input such as example.com?redirect=http://othersite.com then you probably do want to prepend http:// so just searching for :// might not be good enough for a general solution.

    Alternative approaches

    • Using a regular expression:

      if (!s.match(/^[a-zA-Z]+:\/\//))
      {
          s = 'http://' + s;
      }
      
    • Using a URI parsing library such as JS-URI.

      if (new URI(s).scheme === null)
      {
          s = 'http://' + s;
      }
      

    Related questions

    • Javascript equalsIgnoreCase: case insensitive string comparation
    • javascript startswith
    • How do I parse a URL into hostname and path in javascript?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fileupload input field that upload files to. In the matching controller
I have a controller bound the URL: /ruleManagement. Inside my JSP, I have a
I have a parent form which saves the settings and changes user puts. But
I have created a form, quite complex, with user input unique values, integers and
I really didn't know what title to give this question, but I'll explain here:
Simple question from an absolute n00b. I'm trying to create an edit content screen
My issue involves jQuery .post and Joomla. I have a template with a form
Having trouble here and not quite sure how to do it. I've attempted jQuery
I just started experimenting with jqModal and am having a strange issue. The modal
I am using Knockout and the Knockout Mapping plugin. My MVC3 Action returns a

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.