Wednesday, April 3, 2013

trim in javascript

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function isBlank(s)
{
     if(s==null)
     return true;
     if(s.match(/^\s*$/))
     {
         return true
     }
     return false;
}

    if(isBlank(trim(objTourName.value,' ')) || trim(objTourName.value,' ').length ==0)
    {
        alert("Tour Name can not be left blank.");
        objTourName.focus();
        return false;
    }

No comments:

Post a Comment