Skip to content

Commit

Permalink
Adding mb_ functions to Validation methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 8, 2009
1 parent 0d3ef03 commit 2c144a9
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions cake/libs/validation.php
Expand Up @@ -25,7 +25,9 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/

if (!class_exists('Multibyte')) {
App::import('Core', 'Multibyte');
}
/**
* Offers different validation methods.
*
Expand Down Expand Up @@ -183,7 +185,7 @@ function alphaNumeric($check) {
* @access public
*/
function between($check, $min, $max) {
$length = strlen($check);
$length = mb_strlen($check);
return ($length >= $min && $length <= $max);
}

Expand Down Expand Up @@ -238,7 +240,7 @@ function cc($check, $type = 'fast', $deep = false, $regex = null) {
}
$_this->check = str_replace(array('-', ' '), '', $_this->check);

if (strlen($_this->check) < 13) {
if (mb_strlen($_this->check) < 13) {
return false;
}

Expand All @@ -247,20 +249,24 @@ function cc($check, $type = 'fast', $deep = false, $regex = null) {
return $_this->_luhn();
}
}
$cards = array('all' => array('amex' => '/^3[4|7]\\d{13}$/',
'bankcard' => '/^56(10\\d\\d|022[1-5])\\d{10}$/',
'diners' => '/^(?:3(0[0-5]|[68]\\d)\\d{11})|(?:5[1-5]\\d{14})$/',
'disc' => '/^(?:6011|650\\d)\\d{12}$/',
'electron' => '/^(?:417500|4917\\d{2}|4913\\d{2})\\d{10}$/',
'enroute' => '/^2(?:014|149)\\d{11}$/',
'jcb' => '/^(3\\d{4}|2100|1800)\\d{11}$/',
'maestro' => '/^(?:5020|6\\d{3})\\d{12}$/',
'mc' => '/^5[1-5]\\d{14}$/',
'solo' => '/^(6334[5-9][0-9]|6767[0-9]{2})\\d{10}(\\d{2,3})?$/',
'switch' => '/^(?:49(03(0[2-9]|3[5-9])|11(0[1-2]|7[4-9]|8[1-2])|36[0-9]{2})\\d{10}(\\d{2,3})?)|(?:564182\\d{10}(\\d{2,3})?)|(6(3(33[0-4][0-9])|759[0-9]{2})\\d{10}(\\d{2,3})?)$/',
'visa' => '/^4\\d{12}(\\d{3})?$/',
'voyager' => '/^8699[0-9]{11}$/'),
'fast' => '/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$/');
$cards = array(
'all' => array(
'amex' => '/^3[4|7]\\d{13}$/',
'bankcard' => '/^56(10\\d\\d|022[1-5])\\d{10}$/',
'diners' => '/^(?:3(0[0-5]|[68]\\d)\\d{11})|(?:5[1-5]\\d{14})$/',
'disc' => '/^(?:6011|650\\d)\\d{12}$/',
'electron' => '/^(?:417500|4917\\d{2}|4913\\d{2})\\d{10}$/',
'enroute' => '/^2(?:014|149)\\d{11}$/',
'jcb' => '/^(3\\d{4}|2100|1800)\\d{11}$/',
'maestro' => '/^(?:5020|6\\d{3})\\d{12}$/',
'mc' => '/^5[1-5]\\d{14}$/',
'solo' => '/^(6334[5-9][0-9]|6767[0-9]{2})\\d{10}(\\d{2,3})?$/',
'switch' => '/^(?:49(03(0[2-9]|3[5-9])|11(0[1-2]|7[4-9]|8[1-2])|36[0-9]{2})\\d{10}(\\d{2,3})?)|(?:564182\\d{10}(\\d{2,3})?)|(6(3(33[0-4][0-9])|759[0-9]{2})\\d{10}(\\d{2,3})?)$/',
'visa' => '/^4\\d{12}(\\d{3})?$/',
'voyager' => '/^8699[0-9]{11}$/'
),
'fast' => '/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$/'
);

if (is_array($_this->type)) {
foreach ($_this->type as $value) {
Expand Down Expand Up @@ -291,10 +297,10 @@ function cc($check, $type = 'fast', $deep = false, $regex = null) {
* Used to compare 2 numeric values.
*
* @param mixed $check1 if string is passed for a string must also be passed for $check2
* used as an array it must be passed as array('check1' => value, 'operator' => 'value', 'check2' -> value)
* used as an array it must be passed as array('check1' => value, 'operator' => 'value', 'check2' -> value)
* @param string $operator Can be either a word or operand
* is greater >, is less <, greater or equal >=
* less or equal <=, is less <, equal to ==, not equal !=
* is greater >, is less <, greater or equal >=
* less or equal <=, is less <, equal to ==, not equal !=
* @param integer $check2 only needed if $check1 is a string
* @return boolean Success
* @access public
Expand Down Expand Up @@ -588,7 +594,7 @@ function ip($check) {
* @access public
*/
function minLength($check, $min) {
$length = strlen($check);
$length = mb_strlen($check);
return ($length >= $min);
}

Expand All @@ -601,7 +607,7 @@ function minLength($check, $min) {
* @access public
*/
function maxLength($check, $max) {
$length = strlen($check);
$length = mb_strlen($check);
return ($length <= $max);
}

Expand Down Expand Up @@ -890,7 +896,7 @@ function _extract($params) {
$_this->regex = $regex;
}
if (isset($country)) {
$_this->country = strtolower($country);
$_this->country = mb_strtolower($country);
}
if (isset($deep)) {
$_this->deep = $deep;
Expand Down

0 comments on commit 2c144a9

Please sign in to comment.