cvs: pear /Validate Validate.php
| From: | Tomas V.V.Cox | Date: | Sun, 09 Jun 2002 14:37:47 +0000 |
| Subject: | cvs: pear /Validate Validate.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-4503@lists.php.net to get a copy of this message | ||
cox Sun Jun 9 10:37:47 2002 EDT
Modified files:
/pear/Validate Validate.php
Log:
CS
Index: pear/Validate/Validate.php
diff -u pear/Validate/Validate.php:1.14 pear/Validate/Validate.php:1.15
--- pear/Validate/Validate.php:1.14 Thu Jun 6 11:18:03 2002
+++ pear/Validate/Validate.php Sun Jun 9 10:37:47 2002
@@ -18,7 +18,7 @@
// | |
// +----------------------------------------------------------------------+
//
-// $Id: Validate.php,v 1.14 2002/06/06 15:18:03 cox Exp $
+// $Id: Validate.php,v 1.15 2002/06/09 14:37:47 cox Exp $
//
// Methods for common data validations
//
@@ -41,18 +41,14 @@
class Validate
{
-
- function Validate() {
- }
-
/**
* @param mixed $decimal The decimal char or false when decimal not allowed
*/
function number($number, $decimal = null, $dec_prec = null, $min = null, $max = null)
{
- if ( is_array( $number ) )
+ if (is_array($number)) {
extract($number);
-
+ }
$dec_prec = $dec_prec ? "{1,$dec_prec}" : '+';
$dec_regex = $decimal ? "[$decimal][0-9]$dec_prec" : '';
if (!preg_match("|^[-+]?\s*[0-9]+($dec_regex)?\$|", $number)) {
@@ -73,8 +69,9 @@
function email($email, $check_domain = false)
{
- if ( is_array( $email ) )
+ if (is_array($email)) {
extract($email);
+ }
if (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.
'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
@@ -97,9 +94,9 @@
*/
function string($string, $format = null, $min_lenght = 0, $max_lenght = 0)
{
- if ( is_array( $string ) )
+ if (is_array($string)) {
extract($string);
-
+ }
if ($format && !preg_match("|^[$format]*\$|s", $string)) {
return false;
}
@@ -112,22 +109,11 @@
return true;
}
- // move outside
- /*
- function date($date, $format, $min_range = false, $max_range = false)
- {
- if (!include_once 'Date/Date.php') {
- trigger_error(' no date class found ..', E_USER_ERROR);
- return false;
- }
- }
- */
-
function url($url, $domain_check = false)
{
- if ( is_array( $url ) )
+ if (is_array($url)) {
extract($url);
-
+ }
$purl = parse_url($url);
if (preg_match('|^http$|i', @$purl['scheme']) &&
!empty($purl['host'])) {
if ($domain_check && function_exists('checkdnsrr')) {
@@ -188,7 +174,7 @@
*/
function date($date, $format, $min = array(), $max = array())
{
- for ($i = 0; $i < strlen($format); $i++) {
+ for ($i = 0; $i < strlen($format) && strlen($date); $i++) {
$c = $format{$i};
if ($c == '%') {
$next = $format{$i + 1};
@@ -313,23 +299,24 @@
@return array value name => true|false the value name comes from the data key
*/
- function multiple( &$data, &$val_type, $remove = false ) {
+ function multiple(&$data, &$val_type, $remove = false)
+ {
$core_methods =
array('number','string','email','url');
- if( !is_null($data) && !is_null($val_type) ){
-
- $keys = array_keys( $data );
- foreach( $keys as $var_name ) {
- if (isset( $val_type[$var_name] ))
- $opt = $val_type[$var_name];
-
- if ( isset( $opt['type'] ) &&
$opt['type']!="" )
- if ( in_array( $opt['type'], $core_methods ) ){
+ if (!is_null($data) && !is_null($val_type)) {
+ $keys = array_keys($data);
+ foreach ($keys as $var_name) {
+ if (isset($val_type[$var_name])) {
+ $opt = $val_type[$var_name];
+ }
+ if (isset($opt['type']) && $opt['type'] !=
'') {
+ if (in_array( $opt['type'], $core_methods)) {
$opt[$opt['type']] = $data[$var_name];
$valid[$var_name] = Validate::$opt['type']($opt);
} else {
// External call
}
+ }
}
return $valid;
} else {