Validate filters

Listing of filters for validation
ID Name Options Flags Description
FILTER_VALIDATE_BOOLEAN, FILTER_VALIDATE_BOOL "boolean" default FILTER_NULL_ON_FAILURE

Returns true for "1", "true", "on" and "yes". Returns false otherwise.

If FILTER_NULL_ON_FAILURE is set, false is returned only for "0", "false", "off", "no", and "", and null is returned for all non-boolean values.

String values are trimmed using trim() before comparison.

FILTER_VALIDATE_DOMAIN "validate_domain" default FILTER_FLAG_HOSTNAME, FILTER_NULL_ON_FAILURE

Validates whether the domain name label lengths are valid.

Validates domain names against RFC 1034, RFC 1035, RFC 952, RFC 1123, RFC 2732, RFC 2181, and RFC 1123. Optional flag FILTER_FLAG_HOSTNAME adds ability to specifically validate hostnames (they must start with an alphanumeric character and contain only alphanumerics or hyphens).

FILTER_VALIDATE_EMAIL "validate_email" default FILTER_FLAG_EMAIL_UNICODE, FILTER_NULL_ON_FAILURE

Validates whether the value is a valid e-mail address.

In general, this validates e-mail addresses against the addr-specsyntax in » RFC 822, with the exceptions that comments and whitespace folding and dotless domain names are not supported.

FILTER_VALIDATE_FLOAT "float" default, decimal, min_range, max_range FILTER_FLAG_ALLOW_THOUSAND, FILTER_NULL_ON_FAILURE

Validates value as float, optionally from the specified range, and converts to float on success.

String values are trimmed using trim() before comparison.

FILTER_VALIDATE_INT "int" default, min_range, max_range FILTER_FLAG_ALLOW_OCTAL, FILTER_FLAG_ALLOW_HEX, FILTER_NULL_ON_FAILURE

Validates value as integer, optionally from the specified range, and converts to int on success.

String values are trimmed using trim() before comparison.

FILTER_VALIDATE_IP "validate_ip" default FILTER_FLAG_IPV4, FILTER_FLAG_IPV6, FILTER_FLAG_NO_PRIV_RANGE, FILTER_FLAG_NO_RES_RANGE, FILTER_NULL_ON_FAILURE Validates value as IP address, optionally only IPv4 or IPv6 or not from private or reserved ranges.
FILTER_VALIDATE_MAC "validate_mac_address" default FILTER_NULL_ON_FAILURE Validates value as MAC address.
FILTER_VALIDATE_REGEXP "validate_regexp" default, regexp FILTER_NULL_ON_FAILURE Validates value against regexp, a Perl-compatible regular expression.
FILTER_VALIDATE_URL "validate_url" default FILTER_FLAG_SCHEME_REQUIRED, FILTER_FLAG_HOST_REQUIRED, FILTER_FLAG_PATH_REQUIRED, FILTER_FLAG_QUERY_REQUIRED, FILTER_NULL_ON_FAILURE Validates value as URL (according to » http://www.faqs.org/rfcs/rfc2396), optionally with required components. Beware a valid URL may not specify the HTTP protocol http:// so further validation may be required to determine the URL uses an expected protocol, e.g. ssh:// or mailto:. Note that the function will only find ASCII URLs to be valid; internationalized domain names (containing non-ASCII characters) will fail.

Note:

When default is set to option, default's value is used if value is not validated.

Changelog

Version Description
8.0.0 The FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_HOST_REQUIRED flags for the FILTER_VALIDATE_URL filter have been removed. The scheme and host are (and have been) always required.
8.0.0 Added FILTER_VALIDATE_BOOL as an alias for FILTER_VALIDATE_BOOLEAN. Using FILTER_VALIDATE_BOOL is preferred.
7.4.0 Added min_range and max_range options for FILTER_VALIDATE_FLOAT.
7.0.0 Added FILTER_FLAG_HOSTNAME and FILTER_VALIDATE_DOMAIN.

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial