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.
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
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.
@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.
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.
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
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.