<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Validate filters</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="filter.filters.html">Types of filters</a></div> <div class="next" style="text-align: right; float: right;"><a href="filter.filters.sanitize.html">Sanitize filters</a></div> <div class="up"><a href="filter.filters.html">Types of filters</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="filter.filters.validate" class="section"> <h2 class="title">Validate filters</h2> <p class="para"> <table class="doctable table"> <caption><strong>Listing of filters for validation</strong></caption> <thead> <tr> <th>ID</th> <th>Name</th> <th>Options</th> <th>Flags</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td><strong><code>FILTER_VALIDATE_BOOLEAN</code></strong></td> <td>"boolean"</td> <td> <code class="parameter">default</code> </td> <td> <strong><code>FILTER_NULL_ON_FAILURE</code></strong> </td> <td> <p class="para"> Returns <strong><code>TRUE</code></strong> for "1", "true", "on" and "yes". Returns <strong><code>FALSE</code></strong> otherwise. </p> <p class="para"> If <strong><code>FILTER_NULL_ON_FAILURE</code></strong> is set, <strong><code>FALSE</code></strong> is returned only for "0", "false", "off", "no", and "", and <strong><code>NULL</code></strong> is returned for all non-boolean values. </p> </td> </tr> <tr> <td><strong><code>FILTER_VALIDATE_DOMAIN</code></strong></td> <td>"validate_domain"</td> <td> <code class="parameter">default</code> </td> <td> <strong><code>FILTER_FLAG_HOSTNAME</code></strong> </td> <td> <p class="para"> Validates whether the domain name label lengths are valid. </p> <p class="para"> Validates domain names against RFC 1034, RFC 1035, RFC 952, RFC 1123, RFC 2732, RFC 2181, and RFC 1123. Optional flag <strong><code>FILTER_FLAG_HOSTNAME</code></strong> adds ability to specifically validate hostnames (they must start with an alphanumberic character and contain only alphanumerics or hyphens). </p> </td> </tr> <tr> <td><strong><code>FILTER_VALIDATE_EMAIL</code></strong></td> <td>"validate_email"</td> <td> <code class="parameter">default</code> </td> <td> <strong><code>FILTER_FLAG_EMAIL_UNICODE</code></strong> </td> <td> <p class="para"> Validates whether the value is a valid e-mail address. </p> <p class="para"> In general, this validates e-mail addresses against the syntax in RFC 822, with the exceptions that comments and whitespace folding and dotless domain names are not supported. </p> </td> </tr> <tr> <td><strong><code>FILTER_VALIDATE_FLOAT</code></strong></td> <td>"float"</td> <td> <code class="parameter">default</code>, <code class="parameter">decimal</code> </td> <td> <strong><code>FILTER_FLAG_ALLOW_THOUSAND</code></strong> </td> <td>Validates value as float, and converts to float on success.</td> </tr> <tr> <td><strong><code>FILTER_VALIDATE_INT</code></strong></td> <td>"int"</td> <td> <code class="parameter">default</code>, <code class="parameter">min_range</code>, <code class="parameter">max_range</code> </td> <td> <strong><code>FILTER_FLAG_ALLOW_OCTAL</code></strong>, <strong><code>FILTER_FLAG_ALLOW_HEX</code></strong> </td> <td>Validates value as integer, optionally from the specified range, and converts to int on success.</td> </tr> <tr> <td><strong><code>FILTER_VALIDATE_IP</code></strong></td> <td>"validate_ip"</td> <td> <code class="parameter">default</code> </td> <td> <strong><code>FILTER_FLAG_IPV4</code></strong>, <strong><code>FILTER_FLAG_IPV6</code></strong>, <strong><code>FILTER_FLAG_NO_PRIV_RANGE</code></strong>, <strong><code>FILTER_FLAG_NO_RES_RANGE</code></strong> </td> <td> Validates value as IP address, optionally only IPv4 or IPv6 or not from private or reserved ranges. </td> </tr> <tr> <td><strong><code>FILTER_VALIDATE_MAC</code></strong></td> <td>"validate_mac_address"</td> <td> <code class="parameter">default</code> </td> <td class="empty"> </td> <td>Validates value as MAC address.</td> </tr> <tr> <td><strong><code>FILTER_VALIDATE_REGEXP</code></strong></td> <td>"validate_regexp"</td> <td> <code class="parameter">default</code>, <code class="parameter">regexp</code> </td> <td class="empty"> </td> <td> Validates value against <code class="parameter">regexp</code>, a <a href="book.pcre.html" class="link">Perl-compatible</a> regular expression. </td> </tr> <tr> <td><strong><code>FILTER_VALIDATE_URL</code></strong></td> <td>"validate_url"</td> <td> <code class="parameter">default</code> </td> <td> <strong><code>FILTER_FLAG_SCHEME_REQUIRED</code></strong>, <strong><code>FILTER_FLAG_HOST_REQUIRED</code></strong>, <strong><code>FILTER_FLAG_PATH_REQUIRED</code></strong>, <strong><code>FILTER_FLAG_QUERY_REQUIRED</code></strong> </td> <td>Validates value as URL (according to <a href="http://www.faqs.org/rfcs/rfc2396" class="link external">» http://www.faqs.org/rfcs/rfc2396</a>), optionally with required components. Beware a valid URL may not specify the HTTP protocol <em>http://</em> so further validation may be required to determine the URL uses an expected protocol, e.g. <em>ssh://</em> or <em>mailto:</em>. Note that the function will only find ASCII URLs to be valid; internationalized domain names (containing non-ASCII characters) will fail.</td> </tr> </tbody> </table> </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> As of PHP 5.4.11, the numbers +0 and -0 validate as both integers as well as floats (using <strong><code>FILTER_VALIDATE_FLOAT</code></strong> and <strong><code>FILTER_VALIDATE_INT</code></strong>). Before PHP 5.4.11 they only validated as floats (using <strong><code>FILTER_VALIDATE_FLOAT</code></strong>). </p> <p class="para"> When <code class="parameter">default</code> is set to option, <code class="parameter">default</code>'s value is used if value is not validated. </p> </p></blockquote> <div class="simplesect"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>7.3.0</td> <td> Deprecated explicit usage of <strong><code>FILTER_FLAG_HOST_REQUIRED</code></strong> and <strong><code>FILTER_FLAG_SCHEME_REQUIRED</code></strong>. They are implied for <strong><code>FILTER_VALIDATE_URL</code></strong> </td> </tr> <tr> <td>7.0.0</td> <td> Added <strong><code>FILTER_FLAG_HOSTNAME</code></strong> </td> </tr> <tr> <td>5.5.0</td> <td> Added <strong><code>FILTER_VALIDATE_MAC</code></strong> </td> </tr> <tr> <td>5.2.1</td> <td> <strong><code>FILTER_VALIDATE_URL</code></strong> now implicitly uses <strong><code>FILTER_FLAG_SCHEME_REQUIRED</code></strong> and <strong><code>FILTER_FLAG_HOST_REQUIRED</code></strong>. </td> </tr> </tbody> </table> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="filter.filters.html">Types of filters</a></div> <div class="next" style="text-align: right; float: right;"><a href="filter.filters.sanitize.html">Sanitize filters</a></div> <div class="up"><a href="filter.filters.html">Types of filters</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>