Allow Spaces but not other random characters? |
[eluser]Corey Freeman[/eluser]
For my blogging simulator (fun fun), people want to be able to use spaces in their blog's names. I personally want the game to retain some kind of realism by not letting people name their blogs random strings of special characters (e..x "U$%9*$)&%(#*$)*^)( Blog) but I don't see any reason not to allow spaces or something. How do I keep the alphanumeric rule AND allow spaces? And I do know that a space isn't an alphanumeric character.
[eluser]mddd[/eluser]
Just make a custom rule, then you can allow or disallow everything you want.
[eluser]Corey Freeman[/eluser]
I don't know what that custom rule would look like.
[eluser]Jelmer[/eluser]
Something like this: Code: function check_blog_name( $str ) EDIT: that matches anything but a to z, 0 to 9 or spaces (the "i" at the end makes it not care about upper/lowercase), if it finds more then 0 matches that means there are disallowed characters.
[eluser]Buso[/eluser]
http://ellislab.com/codeigniter/user-gui...#callbacks Use a callback to check for your desired regular expression. More useful links: http://php.net/manual/en/function.preg-match.php http://www.regular-expressions.info/quickstart.html
[eluser]Corey Freeman[/eluser]
@buso I know how to use a callback, I just meant I don't know how to check for an empty space. @Jelmer Thanks for the suggestion.
[eluser]cchi[/eluser]
try this regex: [^\s] -this check a whitespace characters or use [^\_] \s - Match any whitespace characters (space, tab etc.) \S - Match any character NOT whitespace (space, tab) ^[\S]*$ - check non whitespace string |
Welcome Guest, Not a member yet? Register Sign In |