Bluehost.com Web Hosting $6.95

validating using php

This is a discussion on validating using php within the PHP General forums, part of the PHP Programming Forums category; thanks to everyone for providing the solution for validating textarea using php i have used the following and it worked $...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-14-2008
Sudhakar
 
Posts: n/a
Default validating using php

thanks to everyone for providing the solution for validating textarea using
php i have used the following and it worked

$add = trim($_POST["add"]);

if(strlen(trim($add)) == 0 )
{
$error.="<br>Please enter your address ";
}


as part of the form the user has to fill in their name, assuming if the user
simply presses the space bar i would like to display a message like the text
area. presently my validation for name is

$name = trim($_POST["name"]);

if( strlen(trim($name) == 0 ) || !preg_match('/^[a-zA-Z ]+$/x', $name) )
{
$error.="Name is blank or has special characters ";
}

with the above code for validating the name if a user types only spaces then
the error message is displayed however if there is a gap in the name example
john smith the error message is appearing which should not be happening as i
have given
preg_match('/^[a-zA-Z ]+$/x', $name) which means the user can type small,
upper case letters and also there can be a space in the name

how can i change the php code = if( strlen(trim($name) == 0 ) ||
!preg_match('/^[a-zA-Z ]+$/x', $name) )

so that i can validate both a) blank spaces and also accept spaces between
the name, i can validate individually for spaces and uses preg_match as 2
separate lines, instead i would like to validate in a single line of php

please advice.

thanks.

Reply With Quote
  #2 (permalink)  
Old 05-14-2008
Iv Ray
 
Posts: n/a
Default Re: [PHP] validating using php

Sudhakar wrote:
> if( strlen(trim($name) == 0 ) || !preg_match('/^[a-zA-Z ]+$/x', $name) )
> {
> $error.="Name is blank or has special characters ";
> }


You have messed up the brackets. This -

strlen(trim($name) == 0 )

should be -

strlen(trim($name)) == 0

Then the script does what you want.

Iv
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:23 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0