URL input validation?

Scope:
So I am asking my users to enter a URL in a form.
The purpose is to show a button (when a URL is present on an entry), that takes them to the URL they supplied.
Simple, right?

Issue:
I’m hitting an issue where any URLs without the ‘http://www.’ protocol will simply open a new tab (via a plugin) with my Bubble URL and the domain appended to the end.
e.g. https://app-name.bubbleapps.io/version-test/index/shop.com
Not great!
URLs following correct format (http://www.shop.com), open the URL as expected.

Currently I have no validation on the input and so the user is free to enter full or part URLs.
So either http://www.shop.com OR shop.com can be entered.
Basically I want to ensure all URLs entered at least have the correct protocols before the domain.

Solution:
What is the best option here?

  1. Input validation using a regex.
  2. On form submit (create new or edit existing entry), do I filter the value and prepend ‘http://www.’ to the URL.

From there, how would I implement each option?
Obviously I would need to check that the ‘http://www.’ doesn’t already exist and then prepend, otherwise ignore and submit as is.
OR
Am I missing something here and I am simply serving the link the incorrect way and there is a way to avoid plain domains being opened in a new tab as an appended path to my app URL?

1 Like

If you know the regex pattern to validate ‘http://www.’ please share it. I put up a post a while back asking if anybody knew it with no responses.

As I had no responses I decided the best way was to make sure my input had the ‘http://www.’ to begin with, so I used a plugin by @AliFarahat that is pretty useful, although there are some issues with the way it works in practice and I haven’t had any luck with the plugin developer shedding light onto the issues.

At this stage, the best thing in my mind was to ignore the poor user experience caused by the plugin and use it anyway and hope for the best on getting some feedback on how to resolve the problems.

After reading your post, I think if you know how to use the regex or a way to prepend the link it would be better.

This I don’t know. You may need to share a link to the editor or some screen shots to get more help on that.

This topic was automatically closed after 70 days. New replies are no longer allowed.