3 Replies - 950 Views - Last Post: 30 September 2012 - 05:57 AM Rate Topic: -----

#1 ettedo2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 26-September 12

Validation of check on empty string

Posted 29 September 2012 - 08:10 PM

Hello,
I am writing a php script that intakes the information of a form and validate the input for the following conditions.
All fields are submitted with data.Names are not empty strings and are not numeric.

I am using following code for checking that field is not empty
if(empty($FirstName) || empty($LastName)) 
{
//output Error message
}


I also use this coad for the numeric validation
else if (is_numeric($FirstName)|| is_numeric($LastName))
{
//output Error message
}


And all that works fine. What I can not figure out is how to make sure that the string is not empty.
I been working on it all day and I still have not figured out how I can make sure if user Inputs
" " or ' ' or "0" it will sent an Error message.
I have tried
else if(string ($FirstName) == " ")
// this gives me a fatal error message
else if (!is_string("FirstName") || !is_string("LastName"))
//nothing happens	



I would appreciate any help. Thank you

Is This A Good Question/Topic? 0
  • +

Replies To: Validation of check on empty string

#2 ettedo2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 26-September 12

Re: Validation of check on empty string

Posted 29 September 2012 - 09:25 PM

Never mind I finally got it.
Thank you to all that where reading the post.
Was This Post Helpful? 0
  • +
  • -

#3 zeeshanef  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 76
  • Joined: 14-April 12

Re: Validation of check on empty string

Posted 30 September 2012 - 03:06 AM

you can use trim!
if(trim($FirstName) == "")
{
}

Was This Post Helpful? 0
  • +
  • -

#4 Nullified  Icon User is offline

  • New D.I.C Head

Reputation: 13
  • View blog
  • Posts: 49
  • Joined: 18-September 12

Re: Validation of check on empty string

Posted 30 September 2012 - 05:57 AM

Mind letting everyone know how you fixed it? Did you try (strlen($str) == 0)? Be aware trim can sometimes cause false positive in some situation such as empty arrays.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1