mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Implementing Validation::ip()
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4265 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
50149aeeed
commit
98f32860a9
1 changed files with 22 additions and 1 deletions
|
@ -477,8 +477,25 @@ class Validation extends Object {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation of an IPv4 address.
|
||||
*
|
||||
* @param string $check The string to test.
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function ip($check) {
|
||||
|
||||
$bytes = explode('.', $check);
|
||||
if (count($bytes) == 4) {
|
||||
$returnValue = true;
|
||||
foreach ($bytes as $byte) {
|
||||
if (!(is_numeric($byte) && $byte >= 0 && $byte <= 255)) {
|
||||
$returnValue = false;
|
||||
}
|
||||
}
|
||||
return $returnValue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -486,6 +503,8 @@ class Validation extends Object {
|
|||
*
|
||||
* @param string $check The string to test
|
||||
* @param int $min The minimal string length
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function minLength($check, $min) {
|
||||
$length = strlen($check);
|
||||
|
@ -497,6 +516,8 @@ class Validation extends Object {
|
|||
*
|
||||
* @param string $check The string to test
|
||||
* @param int $max The maximal string length
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function maxLength($check, $max) {
|
||||
$length = strlen($check);
|
||||
|
|
Loading…
Add table
Reference in a new issue