/    Sign up×
Community /Pin to ProfileBookmark

Is This Valid Url FoolProof Regex ?

Folks,

Check this out from tutorial:

[code]
$website = input($_POST[“site”]);

if (!preg_match(“/b(?:(?:https?|ftp)://|www.)[-a-z0-9+&@#/%?=~_|!:,.;]*[-a-z0-9+&@#/%=~_|]/i”,$website)) {
$websiteErr = “Invalid URL”;
}
[/code]

https://www.tutorialspoint.com/php/php_validation_example.htm

Is it foolproof ? Can I use it in my “Url Submission Form” ? Yes or no ? Regardless, you got a better one ?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@VITSUSAApr 16.2021 — This is good but if you share your exact requirements with us so we can suggest you accordingly.
Copy linkTweet thisAlerts:
@developer_webauthorApr 18.2021 — @VITSUSA#1630461

I gonna give people like you my webform to submit your link on my searchengine. Now you know what I doing.
Copy linkTweet thisAlerts:
@NogDogApr 18.2021 — Do you really want to allow FTP links?

As far as everything else, it appears (to my eye, haven't tested it) that it would allow addresses without the "http://" or "https://" as long as they start with "www.". Not sure you want to have to deal with that variation downstream? Also not sure if the whole thing is being too strict in 2021 allowing only ASCII characters for the entire URL?

As far as what I'd actually do if I were doing this, I'd have to do a fair amount of research -- but probably would search github and such for an existing function that is well documented, well rated, updated reasonably recently, and from a respectable-looking source. Ultimately, I'd probably want to do some minimal check that it at least _looks_ like it's a URL, then use cURL to test if it gets a 200 HTTP response or not.
Copy linkTweet thisAlerts:
@developer_webauthorApr 21.2021 — @NogDog#1630529

Thanks.

But I did not understand this part:

**_"Not sure you want to have to deal with that variation downstream? Also not sure if the whole thing is being too strict in 2021 allowing only ASCII characters for the entire URL?"_**

Care to elaborate ?

You have a good point about fixing to only accept http & https and not ftp or ftps.

I have my own ideas how to achieve this but let's learn from you how you would achieve it so users only submit http & https links. **Er, Yes** ?

PS -

Look at the little (3 foot some inches height), aged 21 or so year old fellow, back in 2001 or so, said "**er ? Yes!**".

I downloaded it on my fone and watch it from time to time for a laugh.

https://www.youtube.com/watch?v=HKybDdGHZHE


PPS - That grass in your profile pic, looks like a field in the north of England. In Yorkshire somewhere. I thought you was a Yank, NogDog.

Still nevermind.
Copy linkTweet thisAlerts:
@developer_webauthorApr 22.2021 — @NogDog

Care to answer my previous post ?
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...