I am looking the best way to add http:// to a submitted url. I have a site that allows users to submit their website url when signing up, the problem is some user type “example.com” some users type “www.example.com” and some type “http(s)://example.com”
What I would like to accomplish is to make sure the end result is “http(s)://example.com” regardless of what they submit.
Is there any way to do this and still account for other things like co.uk or https?
You don’t really need of REGEX. REGEX are often a lot expensive. Here’s a home made function that achieve your goal:
Samples:
Output:
If you have any doubt, please consider adding a comment below.
References: