summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Ellis <rick.ellis@ellislab.com>2008-08-21 00:07:30 +0200
committerRick Ellis <rick.ellis@ellislab.com>2008-08-21 00:07:30 +0200
commitd6b0649f9815e9aefe1f2b6cd3b93dcca53cda80 (patch)
treebc878d0fae85f57ff5575b2b346a7c487e0a157f
parent34d191466fc1436c3ac4560880431ad3d97e9e91 (diff)
Added two new functions: is_natural and is_natural_no_zero
-rw-r--r--system/libraries/Validation.php30
1 files changed, 29 insertions, 1 deletions
diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php
index f5e4d2223..a0423c7b6 100644
--- a/system/libraries/Validation.php
+++ b/system/libraries/Validation.php
@@ -614,7 +614,35 @@ class CI_Validation {
{
return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str);
}
-
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Is a Natural number (0,1,2,3, etc.)
+ *
+ * @access public
+ * @param string
+ * @return bool
+ */
+ function is_natural($str)
+ {
+ return (bool)preg_match( '/^[0-9]+$/', $str);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Is a Natural number, but not a zero (1,2,3, etc.)
+ *
+ * @access public
+ * @param string
+ * @return bool
+ */
+ function is_natural_no_zero($str)
+ {
+ return (bool)preg_match( '/^[1-9]+$/', $str);
+ }
+
// --------------------------------------------------------------------
/**