Skip to content

Instantly share code, notes, and snippets.

@walesmd
Created February 25, 2010 17:11
Show Gist options
  • Select an option

  • Save walesmd/314739 to your computer and use it in GitHub Desktop.

Select an option

Save walesmd/314739 to your computer and use it in GitHub Desktop.
<?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(
'#', '?', '~'
);
$regex_characters = array(
'[0-9]', '[a-zA-Z]', '.'
);
$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