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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:22:04+00:00 2026-06-06T19:22:04+00:00

I am writing my app in JavaScript using Appcelerator’s Titanium IDE. I’ve been working

  • 0

I am writing my app in JavaScript using Appcelerator’s Titanium IDE. I’ve been working on this and trying out Regex for about two hours now. Anyway, My question is this:

I have a URL bar. If the user starts the input with ‘www.’ I want it to add the ‘http://’ in front of it, and if they start with ‘http://’, it would not add it. And, if there is no ‘www.’ either, it would add the full ‘http://www.’.

A practical way of going about this would be something like maybe using Regex (I’ve never used it before, don’t have any experience) or something to see if the first two letters are ‘ht’ or ‘ww’, and if that isn’t a match then it would just add the ‘http://www.’

What I just posted above is what I would think one would do, and I’m most likely sounding entirely mad because it makes no sense. I’m not really asking for the whole code to be written out; I can add the various things, I’m just looking for maybe some code/input that would be useful for me being able to plugin and use/modify.

Thanks!

EDIT: Great responses! I’m sure most-if not all work, so I did my best and upvoted 🙂

  • 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-06T19:22:05+00:00Added an answer on June 6, 2026 at 7:22 pm

    Here is another solution:

    var appendHttpToUrl = function(url){
        var httpwww = "http://www.";
        var rx = /(^http:\/\/|^www\.)/g;
        if(url.indexOf(httpwww) === -1){
          if(url.indexOf("http://") > -1 || url.indexOf("www.") > -1){
            url = url.replace(rx,httpwww);
          }else{
            url = httpwww+url;
          }
        }
        return url;
    }
    

    Here is a demo http://jsfiddle.net/TJn7A/5/.

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

Sidebar

Related Questions

A web app I am writing in JavaScript using node.js. I use Foreman, but
We're writing a web app that relies on Javascript/jQuery. It involves users filling out
I am writing a gtk+ app using Gjs ( Gnome JavaScript bindings ) As
I'm writing a phonegap app for iPhone/Android, heavily using the google maps javascript api.
I am about to start writing a web app for the latest smartphones using
I'm currently writing a twitter client using javascript, then found out many people reminded
I'm writing a Javascript app that is getting an HTML document via AJAX, then
I am writing an app to connect to a third party application using REST
I'm writing a web-app using Python and Pylons. I need a textbox that is
I am using socket.io 8.7. I use Webstorm as IDE for writing my network

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.