Skip to content

Instantly share code, notes, and snippets.

@sajanp
Last active December 12, 2015 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sajanp/4697418 to your computer and use it in GitHub Desktop.
Save sajanp/4697418 to your computer and use it in GitHub Desktop.
CodeIgnitor form validation class to allow only alphanum and spaces. My regex is ABSOLUTELY terrible (whose isn't?), so...this may not work and needs to be tested. If you find that the regex pattern needs to be tweaked, please come back and edit this gist.
<?php
function alpha_num_spaces($subject)
{
$pattern = "#^[A-Z0-9 ]+$#i";
$res = preg_match($pattern, $subject);
if ($res == 1)
{
return TRUE;
}
else
{
return FALSE;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment