I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
There are many more common schemes than http, https and ftp, though - and anyone can register their own on your machine if they want.
This will validate using your regex: https://foo.bar:99999 even though it uses an invalid port, while mailto schemes will only work some of the time (depending on where you use colons and so on, and the need to validate an email address being super complicated). The fact that mailto will work at all is a side-effect of your regex thinking it's a username/password section rather than a scheme, and I expect there are combinations which will fail.
I agree that this will get most cases you're likely to care about, and it's probably better than whatever PHP does with FILTER_VALIDATE_URL, but it's never going to be exhaustive unless you write a URL parser.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
There are many more common schemes than http, https and ftp, though - and anyone can register their own on your machine if they want.
This will validate using your regex:
https://foo.bar:99999
even though it uses an invalid port, whilemailto
schemes will only work some of the time (depending on where you use colons and so on, and the need to validate an email address being super complicated). The fact thatmailto
will work at all is a side-effect of your regex thinking it's a username/password section rather than a scheme, and I expect there are combinations which will fail.I agree that this will get most cases you're likely to care about, and it's probably better than whatever PHP does with
FILTER_VALIDATE_URL
, but it's never going to be exhaustive unless you write a URL parser.