Data::...te::URI(3pm)
π Data::Validate::URI π (that's the Data::...te::URI(3pm) page bestie, come get ur URI validation)
okay so real quick, before we dive in: this is the manual page for Data::Validate::URI, a Perl module that does exactly what it says on the tin. it's giving "input validation but make it cute," and honestly? we ate.
πΈ NAME πΈ
Data::Validate::URI β common url validation methods β¨
π SYNOPSIS π
okay the vibe is: you've got a $suspect string and you want to know if it's a URI. say less.
use Data::Validate::URI qw(is_uri);
if(is_uri($suspect)){
print "Looks like an URI\n";
} else {
print "Not a URI\n";
}
# or as an object
my $v = Data::Validate::URI->new();
die "not a URI" unless ($v->is_uri('foo'));
like. it's that easy. no notes. π
π DESCRIPTION π
so this module collects a bunch of common URI validation routines together so that input validation and untainting is easier and more readable. iconic behavior honestly. π«Ά
the big rule, memorize it: every single function returns an untainted value if the test passes, and returns undef if it fails. that means you should always check for a defined status explicitly. do NOT just assume the return will be true. no cap. fr fr. π
and the value you're testing is always the first argument (and, like, often the only one).
yes bestie there are a bunch of other URI validation modules out there (peep SEE ALSO below π). this one is focused on being fast, lightweight, and relatively 'real-world'. i.e. it's the one you want when you're checking user input and you do not need the URI/URL parsed out into chunks. main character energy.
right now the module focuses on HTTP URIs, since they're arguably the most common. if you have a specialized scheme you'd like supported, let the author know.
β¨ FUNCTIONS β¨
π¦ new β constructor for OO usage
new(%options);
Description
returns a Data::Validator::URI object. this lets you access all the validator function calls as methods without importing them into your namespace or using that clumsy Data::Validate::URI::function_name() format. we love a method call moment. π
Arguments
%optionsβ options to be passed into the underlyingData::Validate::Domainmodule
Returns
returns a Data::Validate::URI object π
π is_uri β is the value a well-formed uri?
is_uri($value);
Description
returns the untainted URI if the test value looks well-formed.
heads up bestie: you might actually want one of the more practical methods likeis_http_urioris_https_uri, because the URI standard (RFC 3986) allows a whole lot of things you probably don't want. π
Arguments
$valueβ the potential URI to test.
Returns
returns the untainted URI on success, undef on failure.
Notes, Exceptions, & Bugs
this function makes no attempt whatsoever to check whether the URI is accessible or 'makes sense' in any meaningful way. it just checks that it's formatted correctly. that's it. that's the job. π
π is_http_uri β is the value a well-formed HTTP uri?
is_http_uri($value, \%options);
Description
this is the specialized version of is_uri() that only likes http:// urls. and because it's specialized, it can also do a much more thorough job validating. also, unlike is_uri(), it's way more concerned with only letting real-world URIs through. things like relative hostnames are allowed by the standards but are probably... not wise. conversely, null paths aren't allowed per RFC 2616 (should be '/' instead), but are allowed by this function. slay, we make our own rules.
this function only works for fully-qualified URIs. /bob.html won't work. see RFC 3986 for the appropriate method to turn a relative URI into an absolute one given its context.
returns the untainted URI if the test value looks well-formed.
π note that you probably want to call this in combo with is_https_uri(). i.e.
print "Good" if(is_http_uri($uri) || is_https_uri($uri));
or just use the convenience method is_web_uri, which is equivalent and faster, because it does the work only once. efficiency queen. β
Arguments
$valueβ the potential URI to test.\%optionsβ options to be passed into the underlyingData::Validate::Domainmodule. if called as a method, the options are ignored.
Returns
returns the untainted URI on success, undef on failure.
Notes, Exceptions, & Bugs
this function makes no attempt to check whether the URI is accessible or 'makes sense' in any meaningful way. it just checks that it's formatted correctly. periodt.
π is_https_uri β is the value a well-formed HTTPS uri?
is_https_uri($value. \%options);
(yes the $value. there is exactly how it's written, don't come for me, that's the page π«Ά)
Description
see is_http_uri() for details. this version only likes the https URI scheme. other than that it is identical to is_http_uri(). twins. π§
Arguments
$valueβ the potential URI to test.\%optionsβ options to be passed into the underlyingData::Validate::Domainmodule. if called as a method, the options are ignored.
Returns
returns the untainted URI on success, undef on failure.
Notes, Exceptions, & Bugs
this function makes no attempt to check whether the URI is accessible or 'makes sense' in any meaningful way. it just checks that it's formatted correctly.
β is_web_uri β is the value a well-formed HTTP or HTTPS uri?
is_web_uri($value, \%options);
Description
this is just a convinience method (that's how it's spelled on the page, bestie, we keep it π) that combines is_http_uri and is_https_uri so you can accept most common real-world URLs. but it's faster, because it does the work only once. two birds, one validation pass. ate.
Arguments
$valueβ the potential URI to test.\%optionsβ options to be passed into the underlyingData::Validate::Domainmodule. if called as a method, the options are ignored.
Returns
returns the untainted URI on success, undef on failure.
Notes, Exceptions, & Bugs
this function makes no attempt to check whether the URI is accessible or 'makes sense' in any meaningful way. it just checks that it's formatted correctly.
π¦ is_tel_uri β is the value a well-formed telephone uri?
is_tel_uri($value);
Description
specialized version of is_uri() that only likes tel: urls. and as a result, it can also do a much more thorough job validating according to RFC 3966. dialing up the accuracy, literally. π
returns the untainted URI if the test value looks well-formed.
Arguments
$valueβ the potential URI to test.
Returns
returns the untainted URI on success, undef on failure.
Notes, Exceptions, & Bugs
this function makes no attempt to check whether the URI is accessible or 'makes sense' in any meaningful way. it just checks that it's formatted correctly.
π₯ SEE ALSO π₯
URI, RFC 3986, RFC 3966, RFC 4694, RFC 4759, RFC 4904
go read the RFCs, bestie. iykyk. π
π«Ά AUTHOR π«Ά
Richard Sonnen <sonnen@richardsonnen.com>.
is_tel_uri by David Dick <ddick@cpan.org>. π
πΈ COPYRIGHT πΈ
Copyright (c) 2005 Richard Sonnen. All rights reserved.
this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie!! no skips, no summarising, every single flag and function accounted for. π β¨
this gem was brought to you by perl v5.38.2, dated 2024-03-04, and last seen being its iconic multi-scheme validating self as Data::...te::URI(3pm). mwah. ππ
π¦ where this page comes from
- debian trixie: libdata-validate-uri-perl 0.07-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdata-validate-uri-perl 0.07-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdata-validate-uri-perl 0.07-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdata-validate-uri-perl 0.07-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms