...

View Full Version : validating textarea using php



sudhakararaog
05-13-2008, 03:35 PM
hi

i need to validate textarea of a html form using php

<textarea name="comments" cols="26" rows="3" id="comments"><?php echo($comments);?></textarea>

presently my php code to validate the text area is

if($comments == "" )
{
$error.="<br>Please enter your comments";
}

with this code if a user hits the space bar once or couple of times as a matter of fact there are no characters entered by the user i do not want this to happen, if a user simply hits the spacebar and does not type anything i should be able to display an alert message.

please advice how i can change the above php code.

thanks.

Mwnciau
05-13-2008, 03:42 PM
Try using this instead:


if ( strlen ( trim ( $comments ) ) == 0 )

_Aerospace_Eng_
05-13-2008, 03:50 PM
I really hope you are taking the proper security measures with your php. From what you posted it looks like you are using register_globals which is a security risk. And if you are putting this stuff into a database and aren't escaping anything then you are open to sql injection.

idalatob
05-13-2008, 08:23 PM
Relax, aero meister. I didnt see any mysql there. ;-)

_Aerospace_Eng_
05-13-2008, 11:53 PM
Relax, aero meister. I didnt see any mysql there. ;-)

I know that, and thats why I said "if".

chaosprime
05-14-2008, 05:03 PM
Could also suggest:



if(!preg_match('/\S/', $comments))



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum