Tuesday, June 05, 2007

JavaScript remove leading and trailing whitespace

  <script type="text/javascript">
    var str = "  java script  ";    
    str = str.replace(/^\s+/g,"");//remove heading whitespace
    str = str.replace(/\s+$/g,"");//remove trailing whitespace
    alert("|"+str+"|");
  </script>
 
Blogger Template Layout Design by [ METAMUSE ] : Code Name Gadget 1.1 Power By freecode-frecode.blogger.com & blogger.com Programming Blogs - BlogCatalog Blog Directory