cvs: pear /Validate Validate.php
| From: | Bertrand Mansion | Date: | Mon, 17 Feb 2003 10:55:15 +0000 |
| Subject: | cvs: pear /Validate Validate.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-8907@lists.php.net to get a copy of this message | ||
mansion Mon Feb 17 05:55:15 2003 EDT
Modified files:
/pear/Validate Validate.php
Log:
Cosmetic changes, fix in phpdoc comments, changed global names.
Index: pear/Validate/Validate.php
diff -u pear/Validate/Validate.php:1.26 pear/Validate/Validate.php:1.27
--- pear/Validate/Validate.php:1.26 Sun Feb 16 23:24:38 2003
+++ pear/Validate/Validate.php Mon Feb 17 05:55:14 2003
@@ -15,29 +15,24 @@
// +----------------------------------------------------------------------+
// | Authors: Tomas V.V.Cox <cox@idecnet.com> |
// | Pierre-Alain Joye <pajoye@phpindex.com> |
-// | |
// +----------------------------------------------------------------------+
//
-// $Id: Validate.php,v 1.26 2003/02/17 04:24:38 pajoye Exp $
+// $Id: Validate.php,v 1.27 2003/02/17 10:55:14 mansion Exp $
//
// Methods for common data validations
//
-/**
-Experimental
-*/
-
-define('VAL_NUM', '0-9');
-define('VAL_SPACE', '\s');
-define('VAL_ALPHA_LOWER', 'a-z');
-define('VAL_ALPHA_UPPER', 'A-Z');
-define('VAL_ALPHA', VAL_ALPHA_LOWER . VAL_ALPHA_UPPER);
-define('VAL_EALPHA_LOWER', VAL_ALPHA_LOWER .
'áéíóúàèìòùäëïöüâêîôûñç');
-define('VAL_EALPHA_UPPER', VAL_ALPHA_UPPER .
'ÁÉÍÓÚÀÈÌÒÙÄËÏÖÜÂÊÎÔÛÑÇ');
-define('VAL_EALPHA', VAL_EALPHA_LOWER . VAL_EALPHA_UPPER);
-define('VAL_PUNCTUATION', VAL_SPACE . '\.,;\:&"\'\?\!\(\)');
-define('VAL_NAME', VAL_EALPHA . VAL_SPACE . "'");
-define('VAL_STREET', VAL_NAME . "/\\ºª");
+define('VALIDATE_NUM', '0-9');
+define('VALIDATE_SPACE', '\s');
+define('VALIDATE_ALPHA_LOWER', 'a-z');
+define('VALIDATE_ALPHA_UPPER', 'A-Z');
+define('VALIDATE_ALPHA', VALIDATE_ALPHA_LOWER . VALIDATE_ALPHA_UPPER);
+define('VALIDATE_EALPHA_LOWER', VALIDATE_ALPHA_LOWER .
'áéíóúàèìòùäëïöüâêîôûñç');
+define('VALIDATE_EALPHA_UPPER', VALIDATE_ALPHA_UPPER .
'ÁÉÍÓÚÀÈÌÒÙÄËÏÖÜÂÊÎÔÛÑÇ');
+define('VALIDATE_EALPHA', VALIDATE_EALPHA_LOWER . VALIDATE_EALPHA_UPPER);
+define('VALIDATE_PUNCTUATION', VALIDATE_SPACE .
'\.,;\:&"\'\?\!\(\)');
+define('VALIDATE_NAME', VALIDATE_EALPHA . VALIDATE_SPACE . "'");
+define('VALIDATE_STREET', VALIDATE_NAME . "/\\ºª");
class Validate
{
@@ -78,7 +73,6 @@
return true;
}
-
/**
* Validate a email
*
@@ -113,24 +107,24 @@
* @param string $string String to validate
* @param array $options Options array where:
* 'format' is the format of the string
- * Ex: VAL_NUM . VAL_ALPHA (see constants)
- * 'min_lenght' minimum length
- * 'max_lenght' maximum length
+ * Ex: VALIDATE_NUM . VALIDATE_ALPHA (see constants)
+ * 'min_length' minimum length
+ * 'max_length' maximum length
*/
function string($string, $options)
{
$format = null;
- $min_lenght=$max_lenght = 0;
- if(is_array($options)){
+ $min_length = $max_length = 0;
+ if (is_array($options)){
extract($options);
}
if ($format && !preg_match("|^[$format]*\$|s", $string)) {
return false;
}
- if ($min_lenght && strlen($string) < $min_lenght) {
+ if ($min_length && strlen($string) < $min_length) {
return false;
}
- if ($max_lenght && strlen($string) > $max_lenght) {
+ if ($max_length && strlen($string) > $max_length) {
return false;
}
return true;
@@ -169,16 +163,8 @@
* http://hysteria.sk/prielom/prielom-12.html#3
(Slovak language)
* http://www.speech.cs.cmu.edu/~sburke/pub/luhn_lib.html
(Perl lib)
*
- * Usage:
- * <?php
- * require_once 'Validate.php';
- * if (Validate::creditCard('credit_card_number')) {
- * // Credit card number is OK
- * }
- * ?>
- *
* @param string $number number (only numeric chars will be considered)
- * @return bool true if number is valid, otherwise false
+ * @return bool true if number is valid, otherwise false
* @author Ondrej Jombik <nepto@pobox.sk>
*/
function creditcard($creditcard)
@@ -248,7 +234,7 @@
case 'Y':
case 'y':
if ($next == 'Y') {
- $year = Validate::_substr($date, 4);
+ $year = Validate::_substr($date, 4);
$year = (int)$year?$year:'';
} else {
$year = (int)(substr(date('Y'), 0, 2) .
@@ -329,18 +315,10 @@
* Validate a ISBN number
*
* This function checks given number according
- * Usage:
- * <?php
- * require_once 'Validate.php';
- * if (Validate::ISBN($myisbn)) {
- * // ISBN is OK
- * }
- * ?>
*
* @param string $isbn number (only numeric chars will be considered)
- * @return bool true if number is valid, otherwise false
- * @author Damein Seguy (dams@nexen.net>,
- * added by Pierre-Alain Joye <paj@pearfr.org>
+ * @return bool true if number is valid, otherwise false
+ * @author Damien Seguy <dams@nexen.net>
*/
function isbn($isbn)
{
@@ -410,7 +388,7 @@
* 'val_type' is not optional
* others validations properties must have the same name as the
function
* parameters.
- * Ex:
array('toto'=>array('type'=>'string','format'='toto@thing.info','min_lenght'=>5));
+ * Ex:
array('toto'=>array('type'=>'string','format'='toto@thing.info','min_length'=>5));
* @param boolean $remove if set, the elements not listed in data will be removed
*
* @return array value name => true|false the value name comes from the data key
@@ -434,7 +412,7 @@
$method = $opt['type'];
$opt = array_slice($opt,1);
- if(sizeof($opt)==1){
+ if (sizeof($opt) == 1){
$opt = array_pop($opt);
}
$valid[$var_name] = call_user_func(array('Validate', $method),
$val2check,$opt);
@@ -447,10 +425,9 @@
} elseif (strpos($opt['type'],'_') !== false) {
list($class, $method) = explode('_', $opt['type'], 2);
$class = strtoupper($class);
- @include_once "Validate/$class.php";
- if ( !class_exists("Validate_$class")||
- !in_array($method, get_class_methods("Validate_$class")))
- {
+ @include_once("Validate/$class.php");
+ if (!class_exists("Validate_$class") ||
+ !in_array($method, get_class_methods("Validate_$class"))) {
trigger_error("Invalid validation type Validate_$class::$method",
E_USER_WARNING);
continue;
}
@@ -462,4 +439,4 @@
return $valid;
}
}
-?>
+?>
\ No newline at end of file