Changeset 2585

Show
Ignore:
Timestamp:
04/28/08 11:43:32 (2 months ago)
Author:
Shadowhand
Message:

Added Validation::regex() to do simple regex checks on fields

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/system/libraries/Validation.php

    r2497 r2585  
    626626        } 
    627627 
     628        /** 
     629         * Rule: regex. Generates an error if the field does not match a specific regular 
     630         * expression. 
     631         * 
     632         * @param   string  field value 
     633         * @param   array   regular expression 
     634         * @return  bool 
     635         */ 
     636        public function regex($value, array $patterns) 
     637        { 
     638                $patterns = preg_quote(implode(',', $patterns), '!'); 
     639 
     640                if (preg_match('![^'.$patterns.']+!', $value)) 
     641                { 
     642                        return FALSE; 
     643                } 
     644 
     645                return TRUE; 
     646        } 
     647 
    628648} // End Validation