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 🙂
Here is another solution:
Here is a demo http://jsfiddle.net/TJn7A/5/.