PDA

View Full Version : Checking for spaces


Nightfire
09-10-2002, 07:10 PM
How can I show an error if someone has entered a space in the following

<input type="text" name="name">

I know how to show an error if they put nothing or a space, but I mean if they put

my name

into the text box. How can I tell them that no spaces are allowed in an error?

ShriekForth
09-10-2002, 08:48 PM
You could use split, or explode, then count the number of items in the array it returns.

$words = explode(" ", $name);
if (count($words) > 0){
//Error message
}

ShriekForth

firepages
09-11-2002, 02:43 AM
you could also use strstr()

if(strstr($HTTP_POST_VARS['name'], ' ')){
//error//
}else{
}


or & this is what I usually do (assuming you have told the user not to use spaces already) just replace the spaces with an underscore or similar, and inform them of such.

$HTTP_POST_VARS['name']=str_replace(' ','_',$HTTP_POST_VARS['name']);

Nightfire
09-11-2002, 02:45 AM
Thanks :)