Created
February 25, 2010 17:17
-
-
Save walesmd/314747 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php if (!defined('BASEPATH')) exit('No direct script access allowed.'); | |
| class MY_Form_validation extends CI_Form_validation { | |
| function MY_Form_validation() { | |
| parent::CI_Form_validation(); | |
| } | |
| // matches_pattern() | |
| // Ensures a string matches a basic pattern | |
| // # numeric, ? alphabetical, ~ any character | |
| function matches_pattern($str, $pattern) { | |
| $characters = array( | |
| '[', ']', '\\', '^', '$', | |
| '.', '|', '+', '(', ')', | |
| '#', '?', '~' // Our additional characters | |
| ); | |
| $regex_characters = array( | |
| '\[', '\]', '\\\\', '\^', '\$', | |
| '\.', '\|', '\+', '\(', '\)', | |
| '[0-9]', '[a-zA-Z]', '.' // Our additional characters | |
| ); | |
| $pattern = str_replace($characters, $regex_characters, $pattern); | |
| if (preg_match('/^' . $pattern . '$/', $str)) return TRUE; | |
| return FALSE; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment