[thelist] [JS] Truly checking for empty fields

Joshua Olson joshua at waetech.com
Thu Apr 15 10:14:56 CDT 2004


> -----Original Message-----
> From: Stephen Rider
> Sent: Thursday, April 15, 2004 10:56 AM
>
> Okay, but doesn't deleting all spaces jam words together?
>
> I would think that trimming the value would be the better solution.

Steve,

That doesn't really matter in this instance since you're comparing it
against the empty string with the goal of determining if the field is empty
or not.  But, here's a function that I've had great luck with:

function isWhitespace(str)
{
  try
  {
    var regex = /^\s+$/;
    return regex.test(str);
  }
  catch(er)
  {
    return true;
  }
}

Best of luck,

<><><><><><><><><><>
Joshua Olson
Web Application Engineer
WAE Tech Inc.
http://www.waetech.com/service_areas/
706.210.0168




More information about the thelist mailing list