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:
dho 2007-01-06 16:37:03 +00:00
parent 50149aeeed
commit 98f32860a9

View file

@ -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);