CodeIgniter Forums
Form_validation: How do I not allow spaces? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Form_validation: How do I not allow spaces? (/showthread.php?tid=13926)



Form_validation: How do I not allow spaces? - El Forum - 12-11-2008

[eluser]dallen33[/eluser]
I want users to register a username with no spaces and only allow A-Z and 0-9, no other characters. How do I use the form_validation to make sure the user submits with the rule as stated above?


Form_validation: How do I not allow spaces? - El Forum - 12-11-2008

[eluser]dallen33[/eluser]
I just noticed in the form_validation there is:
Code:
function alpha_numeric($str)
    {
        return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE;
    }
Which is perfect for me wanting to limit it to a-z and 0-9. I think I should be able to make a function that limits spaces. I'll post back if I'm successful.