From d6b0649f9815e9aefe1f2b6cd3b93dcca53cda80 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 20 Aug 2008 22:07:30 +0000 Subject: Added two new functions: is_natural and is_natural_no_zero --- system/libraries/Validation.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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); + } + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b