<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>
You are here: Home > regex > JavaScript remove leading and trailing whitespace