Validating URL Input

whats the best way to validate that a user is inputting a working url into an input form?

not their email, not a mistyped url (ww.bubble.is), not something else like their name or phone.

surprised this is not part of the standard feature set. @emmanuel

2 Likes

This functionality or feature as you describe does exist, the :extract with Regex operation can be used to validate any string.

You might find if you’re looking to validate your URL’s ‘offline’ using regex, that can actually be a fairly complex task that can will often generate false positives. Regex is great for finding predicable patterns, but you’ll find that the URLs that users might want to input on your form will be somewhat diverse.

http://bubble.is
https://www.bubble.is
www.bubble.is
bubble.is

These might be ‘valid’ URLs in the eyes of user and they may even work in their browser.

Would you guess that this url below is valid?

names.club

It is.

There are numerous threads about the virtues of programatic URL validation on stackexchange and elsewhere.

You gave us ww.bubble.is as an example of a bad URL, but it could absolutely be a valid since 'ww' might be a legitimate subdomain of bubble.is

How strict are you looking to be with your submitted URLs? Do you wish to require that your users type in http:// or https:// prefixes before the URL? Seems like a potential pain point for the user who has just filled out the form using bubble.is or google.com and they can’t proceed without figuring out your site’s URL validation rules

Perhaps there is an API, which can go out and check the pages, but this seems awfully server-heavy for a public-facing form

Just my 2 cents :slight_smile:

2 Likes

Hey @jon2,

thanks for your super thoughtful reply! and you’re 100% right. what i’m trying to do is prevent people from entering their email or something nonsensical like inst-ausername@instagram or @twitterhandle.

you have any thoughts on best practices there?

thanks a million!
Sascha

Here’s a comparison of pure regexes that might fit the bill:

https://mathiasbynens.be/demo/url-regex

2 Likes

As a left field suggestion … use the “Link Preview” plugin to generate an image and ask "Is this the website you were thinking of " ?

1 Like

@NigelG thats a great idea. doesn’t quite work for my use case. i want to prevent people form just putting their username or something weird into let’s say instagram or twitter url field.

correct:

incorrect:

  • supermombartz
  • @supermombartz
  • supermombartz@instagram

@keith thanks this is super great! do you know how integrate that regex into a workflow in bubble?

I explain the regex below but you might want to also consider a UX solution to make this easier on your users. I’ve seen this before and it seems fairly elegant.

https://cl.ly/056ebe9a609b/Image%202019-08-04%20at%2012.22.18%20PM.png

The user immediately knows what they need to type into the box.

You can then concatenate the results of hπps://www.instagram.com and input a’s value

It has the side benefit of more simple regex too since you can simply match for a-z and whatever other characters are allowed.

Bubble Regex
Bubble’s built-in regex function is designed so that it can search through
a single string and return multiple items.

i.e.“quick brown fox” (delimited by spaces) could be turned into a list of texts
quick
brown
fox

You want to match a single entry, however, which bubble regex will do, but you’ll want to use the :count function and have bubble evaluate as true when :count is 1

https://cl.ly/601006f8d920/Image%202019-08-04%20at%2012.07.07%20PM.png

image

You’ll probably want to check your regex outside of bubble first since it is easier to tweak and see the exact effect of the changes you are making. You can use a site such as https://regex101.com/ (there are many others like this) to test out your regex.

3 Likes

@jon2 thanks so so much! i’ll give it a try! and definitely good point on the insta url UX!

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