Adding FQDN, hostname, domain, and is_ip verify tests
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1341 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
62
verify.php
62
verify.php
@@ -9,6 +9,15 @@ class verify
|
||||
/////////////////
|
||||
// NETWORK //
|
||||
/////////////////
|
||||
/** Check if $val is a valid IPv4
|
||||
Return TRUE or FALSE */
|
||||
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 */
|
||||
public function is_ipv4 ($val)
|
||||
@@ -27,6 +36,59 @@ class verify
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/** Check if $val is a valid hostname (without domain)
|
||||
Return TRUE or FALSE */
|
||||
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 */
|
||||
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 */
|
||||
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 //
|
||||
///////////////
|
||||
|
||||
Reference in New Issue
Block a user