Ensure correct URL formula Help

Hello, my goal is to create a formula that says:
-if the input is empty, let the output be empty
-If the input is not empty, check if the input contains http
-if not add http:// to the beginning of the input, if it does leave as is.

for example, this is the desired result for each input
input: output:
input: google.com output: https://google.com
input: https://google.com output:https://google.com

I have tried this formula but no success. The use case is that i am adding to a webflow url field, and if the url is not the exact right format, the scenario breaks.
If anyone knows the formula, please provide a screenshot.

It may or may not be making a difference, but my input is in the formula (get ( X; i) (get the i’th value of the list of X)

Welcome to the Make community!

see Can I add "https://" to a variable without it? - #3 by samliew

also, you should check the length is equal to 0 instead of ""

samliewrequest private consultation

Join the unofficial Make Discord server to chat with us!

1 Like

Thank you for your help! it adds https:// to links without it.

However, it is a form field so if its submitted left blank, I want the output to be blank however with your formula:

https://{{ replace(1.url; "/^https?:\/\//"; emptystring) }}

when there is no url the output is is https:// instead of nothing. Please are you able to send an updated formula that accounts for no url?


In that case you’ll need two replace functions:

{{ replace("https://" + replace(1.url; "/^https?:\/\//i"; emptystring); "/^https:\/\/$/i"; emptystring) }}

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

1 Like

Thank you, its leaving blank urls empty but unfortunately the https:// isn’t being added anymore:



Oops, there should be one more set of https!

{{ replace("https://" + replace(1.url; "/^https?:\/\//i"; emptystring); "/^https:\/\/$/i"; emptystring) }}

Input

Screenshot_2024-06-25_170648

Output

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

3 Likes

Haha it is a bit confusing isn’t it. Its working perfectly now thanks so much!

1 Like