Forum Moderators: coopster

Message Too Old, No Replies

isempty validation

to handle multiple space chars and more

         

neophyte

1:51 am on Aug 15, 2007 (gmt 0)

10+ Year Member



Hello All -

I'm trying to fine-tune my validation functions and am starting with empty text and textfield submissions.

So far I've got a very simple function that just checks if the value submitted is empty, or contains 1 empty space character:

function isEmpty($string)
{
return empty($string) ¦¦ $string == ' '? 1 : 0;
}

Right now, if the user inputs 2 or more space characters this function returns FALSE (the field has content) which is not what I want. Ideally, I'd like to improve this function up to handle multiple space characters as well as tab, new-line, return characters, etc.

Can someone please help guide me on how I can make this one function as bullet-proof as possible?

Thanks to all in advance!

Neophyte

cameraman

9:20 am on Aug 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try
return empty(trim [us2.php.net]($string))? 1:0;