Update of /cvsroot/phpweather/phpweather/config
In directory usw-pr-cvs1:/tmp/cvs-serv17011
Modified Files:
pw_validator_range.php
Log Message:
Documentation plus some minor bugfixes.
Index: pw_validator_range.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/config/pw_validator_range.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- pw_validator_range.php 9 Apr 2002 23:21:37 -0000 1.2
+++ pw_validator_range.php 12 Apr 2002 22:07:11 -0000 1.3
@@ -1,31 +1,62 @@
<?
-
+/**
+ * Validates an integer.
+ *
+ * This class checks that an interger is in a given range. This is
+ * usefull for testing port-numbers (range 1--65536) or peoples age
+ * (range 1--120) etc.
+ *
+ */
class pw_validator_range extends pw_validator {
+ /**
+ * The lower bound in the range
+ * @var integer
+ * @access private
+ */
var $low;
+
+ /**
+ * The upper bound in the range
+ * @var integer
+ * @access private
+ */
var $high;
- var $empty_ok;
+ /** You might want to allow the empty string as valid input.
+ * @var boolean
+ * @access private
+ */
+ var $empty_ok;
+
+ /**
+ * Constructs a new validator.
+ *
+ * @param string $error The message displayed when invalid input is given.
+ * @param integer $low The lower bound of the range.
+ * @param integer $high The upper bound of the range.
+ * @param boolean $empty_ok Is the empty string valid?
+ */
function pw_validator_range($error, $low, $high, $empty_ok = false) {
$this->pw_validator($error);
$this->low = $low;
$this->high = $high;
$this->empty_ok = $empty_ok;
}
-
+
function validate($value) {
$this->value = $value;
if ($this->empty_ok && empty($value)) return true;
- return (ereg('^[0-9]+$', $value) && $this->low <= $value && $value <= $this->high);
+ return (ereg('^[-+]?[0-9]+$', $value) && $this->low <= $value && $value <= $this->high);
}
function get_javascript($id) {
+ $empty_ok = $this->empty_ok ? '1' : '0';
return "validate_range('" . addslashes($this->error) .
- "', $this->low, $this->high, $this->empty_ok, '$id', this)";
+ "', $this->low, $this->high, $empty_ok, '$id', this)";
}
-
}
?>
|