Open Source & Stuff  
  |     Main Site     |      Forum     |     Contact     |
Java script :  forum.Salix.gr forum.Salix.gr
Little scripts that might be helpful. It's more like a repository of commonly used functions. Have something you want to share? post it here!! 
Goto Thread: PreviousNext
Goto: Forum ListMessage ListNew TopicSearchLog In
messageCheck empty string
Posted by: panos (IP Logged)
Date: July 07, 2006 04:07PM

This function checks if a string is empty. Empty is also the string " ".
    function isEmptyStr(testStr) {
        var reg1;
        var outVal=true;

        reg1= "^ *$";
        re = new RegExp(reg1);
        if( !re.test(testStr) )
            outVal = false;
        return(outVal);
    }

messageRe: Check empty string
Posted by: panos (IP Logged)
Date: November 30, 2006 09:58AM

A more modern and elegant approach is:

Add a trim function to String prototype:

        /* Strip whitespace from the beginning and end of a string */
        if (typeof String.prototype.trim == "undefined") {
            String.prototype.trim = function () {
                var s = this.replace(/^\s*/, "");
                return s.replace(/\s*$/, "");
            }
        }

And then simply

    if( txt.trim()=='' ) {
         alert('empty text!!');
    }



Sorry, only registered users may post in this forum.

All Rights Reserved 2006 Salix.gr  |  Design by Ades Design |  Hosting by e-emporio |  forum.Salix.gr powered by Phorum