git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1643 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
133 lines
3.4 KiB
PHP
133 lines
3.4 KiB
PHP
<?php
|
|
/** DomDNS
|
|
@package domdns
|
|
@author Dominique Fournier <dominique@fournier38.fr> */
|
|
|
|
/** Permit to check the validity of fields */
|
|
class verify
|
|
{
|
|
/////////////////
|
|
// NETWORK //
|
|
/////////////////
|
|
/** Check if $val is a valid IPv4
|
|
Return TRUE or FALSE
|
|
@param string $val The IP to test */
|
|
public function is_ip ($val)
|
|
{
|
|
if (filter_var ($val, FILTER_VALIDATE_IP))
|
|
return TRUE;
|
|
return FALSE;
|
|
}
|
|
|
|
/** Check if $val is a valid IPv4
|
|
Return TRUE or FALSE
|
|
@param string $val The IPv4 to test */
|
|
public function is_ipv4 ($val)
|
|
{
|
|
if (filter_var ($val, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))
|
|
return TRUE;
|
|
return FALSE;
|
|
}
|
|
|
|
/** Check if $val is a valid IPv6
|
|
Return TRUE or FALSE
|
|
@param string $val The IPv to test */
|
|
public function is_ipv6 ($val)
|
|
{
|
|
if (filter_var ($val, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
|
|
return TRUE;
|
|
return FALSE;
|
|
}
|
|
|
|
/** Check if $val is a valid hostname (without domain)
|
|
Return TRUE or FALSE
|
|
@param string $val The hostname to check */
|
|
public function is_hostname ($val)
|
|
{
|
|
if (strlen ($val) < 2 || strlen ($val) > 128)
|
|
return FALSE;
|
|
if (strspn ($val, "abcdefghijklmnopqrstuvwxyz".
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".
|
|
"0123456789-.") !==
|
|
strlen ($val))
|
|
return FALSE;
|
|
// No end dot ?
|
|
if (substr ($val, -1) === ".")
|
|
return FALSE;
|
|
return TRUE;
|
|
}
|
|
|
|
/** Check if $val is a valid domain (without hostname)
|
|
Return TRUE or FALSE
|
|
@param string $val The domain to check */
|
|
public function is_domain ($val)
|
|
{
|
|
if (strlen ($val) < 2 || strlen ($val) > 128)
|
|
return FALSE;
|
|
if (strspn ($val, "abcdefghijklmnopqrstuvwxyz".
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".
|
|
"0123456789-.") !==
|
|
strlen ($val))
|
|
return FALSE;
|
|
// No end dot ?
|
|
if (substr ($val, -1) === ".")
|
|
return FALSE;
|
|
return TRUE;
|
|
}
|
|
|
|
/** Check if $val is a valid FQDN
|
|
Return TRUE or FALSE
|
|
@param string $val The FQDN to check */
|
|
public function is_FQDN ($val)
|
|
{
|
|
if (strlen ($val) < 2 || strlen ($val) > 255)
|
|
return FALSE;
|
|
if ($this->is_ip ($val))
|
|
return FALSE;
|
|
if (strspn ($val, "abcdefghijklmnopqrstuvwxyz".
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".
|
|
"0123456789-.") !==
|
|
strlen ($val))
|
|
return FALSE;
|
|
// No end dot ?
|
|
if (substr ($val, -1) === ".")
|
|
return FALSE;
|
|
return TRUE;
|
|
}
|
|
|
|
///////////////
|
|
// DATES //
|
|
///////////////
|
|
/** Check if $val is a valid date
|
|
A valid date is 2014-03-20 12:27:34
|
|
Return TRUE or FALSE
|
|
@param string $val The date to check */
|
|
public function is_datetimeSQL ($val)
|
|
{
|
|
if (strlen ($val) !== 19)
|
|
return FALSE;
|
|
$arr = date_parse ($val);
|
|
if ($arr["warning_count"] !==0)
|
|
return FALSE;
|
|
if ($arr["error_count"] !==0)
|
|
return FALSE;
|
|
if (isset ($arr["tz_abbr"]))
|
|
return FALSE;
|
|
if (strspn ($val, "0123456789 :-") !== strlen ($val))
|
|
return FALSE;
|
|
return TRUE;
|
|
}
|
|
|
|
/////////////////
|
|
// NUMBERS //
|
|
/////////////////
|
|
/** Return TRUE if the provided value is an integer in decimal (not octal)
|
|
@param string $val The Integer val to check */
|
|
public function is_integer ($val)
|
|
{
|
|
if (strspn ($val, "0123456789") !== strlen ($val))
|
|
return FALSE;
|
|
return TRUE;
|
|
}
|
|
}
|